Alibaba cloud Kubernetes CSI practice - static NAS volume

Keywords: Web Server Nginx VPC

Environmental preparation

For cluster creation, dependency configuration and CSI plug-in deployment, please refer to: CSI deployment details

Create NAS volume

To create a NAS disk in the NAS console: Reference document

To create a NAS mount point on the NAS console: Reference document

Note: the NAS mount point needs to be in the same vpc as the cluster node;

Create static PV, PVC

Create static volume PV, PVC through the following template:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: nas-pvc
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 5Gi
---
apiVersion: v1
kind: PersistentVolume
metadata:
  name: nas-csi-pv
spec:
  capacity:
    storage: 5Gi
  accessModes:
    - ReadWriteOnce
  persistentVolumeReclaimPolicy: Retain
  csi:
    driver: nasplugin.csi.alibabacloud.com
    volumeHandle: 0790b4a325
    volumeAttributes:
      host: "0790b4a325-xyn4.cn-hangzhou.nas.aliyuncs.com"
      path: "/csi"
      vers: "3"

The drive type is: nasplugin.csi.alibabacloud.com, which means using the alicloud NAS CSI plug-in;

volumeHandle: PV Handler, which can be configured as a random value;

host, path, and vers: indicate NAS mount point, Mount subdirectory, and NAS target version respectively;

# kubectl get pvc
NAME      STATUS   VOLUME       CAPACITY   ACCESS MODES   STORAGECLASS   AGE
nas-pvc   Bound    nas-csi-pv   5Gi        RWO                           34m

# kubectl get pv
NAME         CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS   CLAIM             STORAGECLASS   REASON   AGE
nas-csi-pv   5Gi        RWO            Retain           Bound    default/nas-pvc                           34m

Create application

apiVersion: apps/v1
kind: Deployment
metadata:
  name: nginx-nas
  labels:
    app: nginx
spec:
  selector:
    matchLabels:
      app: nginx
  template:
    metadata:
      labels:
        app: nginx
    spec:
      containers:
      - name: nginx
        image: nginx:1.7.9
        ports:
        - containerPort: 80
        volumeMounts:
          - name: nas-pvc
            mountPath: "/data"
      volumes:
        - name: nas-pvc
          persistentVolumeClaim:
            claimName: nas-pvc

Verify mount, high availability

See pod,Verification NAS Mount successfully, create test file;
# kubectl get pod
NAME                         READY   STATUS    RESTARTS   AGE
nginx-nas-6744df4f6b-krqc2   1/1     Running   0          20m

# kubectl exec nginx-nas-6744df4f6b-krqc2 mount | grep nfs
0790b4a325-xyn4.cn-hangzhou.nas.aliyuncs.com:/csi on /data type nfs (rw,relatime,vers=3,rsize=1048576,wsize=1048576,namlen=255,hard,nolock,noresvport,proto=tcp,timeo=600,retrans=2,sec=sys,mountaddr=192.168.1.252,mountvers=3,mountport=4002,mountproto=tcp,local_lock=all,addr=192.168.1.252)

# kubectl exec nginx-nas-6744df4f6b-krqc2 ls /data
# kubectl exec nginx-nas-6744df4f6b-krqc2 touch /data/test
# kubectl exec nginx-nas-6744df4f6b-krqc2 ls /data
test

//Delete the Pod and check whether the reconstructed Pod data is stable;
# kubectl delete pod nginx-nas-6744df4f6b-krqc2
pod "nginx-nas-6744df4f6b-krqc2" deleted

# kubectl get pod
NAME                         READY   STATUS    RESTARTS   AGE
nginx-nas-6744df4f6b-d6ds9   1/1     Running   0          10s

# kubectl exec nginx-nas-6744df4f6b-d6ds9 ls /data
test

Posted by rascle on Tue, 29 Oct 2019 08:14:59 -0700