Creating stateful applications with NAS dynamic storage volumes

Posted by baselinej on Wed, 11 Dec 2019 06:31:35 +0100

Introduction:

At present, the realization of dynamically generating NAS storage volume: on an existing file system, automatically generating sub file system (sub directory), and generating target storage volume (PV);

The name of the PV generated is: PVC - ${PV uid}

Image introduction:

registry.cn-hangzhou.aliyuncs.com/acs/alicloud-nas-controller:v3.1.0-k8s1.11

Deployment:

Create a NAS file system and add mount points before deployment. Note: the mount point needs to be in the same VPC as the cluster.

In the deployment template, when creating a Storageclass, you can define the reclaimPolicy type, which can be Retain or Delete;

Modify the values of NFS server and server according to the NAS mount point;

apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: alicloud-nas
mountOptions:
- vers=4.0
provisioner: alicloud/nas
reclaimPolicy: Retain

---
kind: Deployment
apiVersion: extensions/v1beta1
metadata:
  name: alicloud-nas-controller
  namespace: kube-system
spec:
  replicas: 1
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: alicloud-nas-controller
    spec:
      tolerations:
      - effect: NoSchedule
        operator: Exists
        key: node-role.kubernetes.io/master
      - effect: NoSchedule
        operator: Exists
        key: node.cloudprovider.kubernetes.io/uninitialized
      nodeSelector:
         node-role.kubernetes.io/master: ""
      serviceAccount: admin
      containers:
        - name: alicloud-nas-controller
          image: registry.cn-hangzhou.aliyuncs.com/acs/alicloud-nas-controller:v3.1.0-k8s1.11
          volumeMounts:
          - mountPath: /persistentvolumes
            name: nfs-client-root
          env:
            - name: PROVISIONER_NAME
              value: alicloud/nas
            - name: NFS_SERVER
              value: 0cd8b4a576-mmi32.cn-hangzhou.nas.aliyuncs.com
            - name: NFS_PATH
              value: /
      volumes:
        - name: nfs-client-root
          nfs:
            server: 0cd8b4a576-mmi32.cn-hangzhou.nas.aliyuncs.com
            path: /

Test:

apiVersion: apps/v1beta1
kind: StatefulSet
metadata:
  name: web
spec:
  serviceName: "nginx"
  replicas: 2
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:alpine
        volumeMounts:
        - mountPath: "/data"
          name: html
  volumeClaimTemplates:
  - metadata:
      name: html
    spec:
      accessModes:
        - ReadWriteOnce
      storageClassName: alicloud-nas
      resources:
        requests:
          storage: 2Gi
# kubectl get pv
NAME                                       CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS    CLAIM                STORAGECLASS          REASON    AGE
pvc-945ca15d-e0ab-11e8-9d2f-00163e145c08   2Gi        RWO            Retain           Bound     default/html-web-0   alicloud-nas-retain             13m
pvc-9a162bb2-e0ab-11e8-9d2f-00163e145c08   2Gi        RWO            Retain           Bound     default/html-web-1   alicloud-nas-retain             13m

Topics: Web Server Nginx Kubernetes VPC