Environmental preparation
For cluster creation, dependency configuration and CSI plug-in deployment, please refer to: CSI deployment details
Create dynamic PV
Create a dynamic volume PV from the following template:
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: disk-pvc spec: accessModes: - ReadWriteOnce resources: requests: storage: 25Gi storageClassName: alicloud-disk-ssd
storage: defines the size of the application cloud disk, with a minimum of 20Gi;
storageClassName: defines the storage class used to create the cloud disk. Currently, it mainly supports the following four types of cloud disk.
Alicloud disk available: will try to create cloud disks in order of efficiency, ssd and essd;
Alicloud disk essd: create an essd type cloud disk;
Alicloud disk ssd: create a cloud disk of ssd type;
Alicloud disk efficiency: create an efficient cloud disk;
View PVC and PV: the name of PV generated by default = PVC + "-" + PVC UID
# kubectl get pvc NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE disk-pvc Bound pvc-5e90da27-a458-11e9-8dec-00163e0a6ecc 25Gi RWO alicloud-disk-ssd 9s # kubectl get pv NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE pvc-5e90da27-a458-11e9-8dec-00163e0a6ecc 25Gi RWO Retain Bound default/disk-pvc alicloud-disk-ssd 8s # kubectl describe pv pvc-5e90da27-a458-11e9-8dec-00163e0a6ecc Name: pvc-5e90da27-a458-11e9-8dec-00163e0a6ecc Labels: <none> Annotations: pv.kubernetes.io/provisioned-by: diskplugin.csi.alibabacloud.com Finalizers: [kubernetes.io/pv-protection] StorageClass: alicloud-disk-ssd Status: Bound Claim: default/disk-pvc Reclaim Policy: Retain Access Modes: RWO VolumeMode: Filesystem Capacity: 25Gi Node Affinity: <none> Message: Source: Type: CSI (a Container Storage Interface (CSI) volume source) Driver: diskplugin.csi.alibabacloud.com VolumeHandle: d-bp190t0frv9044z60t79 ReadOnly: false VolumeAttributes: storage.kubernetes.io/csiProvisionerIdentity=1562849418025-8081-diskplugin.csi.alibabacloud.com type=cloud_ssd Events: <none>
Create application
apiVersion: apps/v1 kind: Deployment metadata: name: nginx-disk 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: disk-pvc mountPath: "/data" volumes: - name: disk-pvc persistentVolumeClaim: claimName: disk-pvc
Verify mount, high availability
See pod,Verify that the cloud disk is successfully mounted and create a test file; # kubectl get pod NAME READY STATUS RESTARTS AGE nginx-disk-6d5659d745-vl4c4 1/1 Running 0 24s # kubectl exec nginx-disk-6d5659d745-vl4c4 ls /data lost+found # kubectl exec nginx-disk-6d5659d745-vl4c4 mount | grep /data /dev/vdc on /data type ext4 (rw,relatime,data=ordered) # kubectl exec nginx-disk-6d5659d745-vl4c4 touch /data/test # kubectl exec nginx-disk-6d5659d745-vl4c4 ls /data lost+found test //Delete the Pod and check whether the reconstructed Pod data is stable; # kubectl delete pod nginx-disk-6d5659d745-vl4c4 pod "nginx-disk-6d5659d745-vl4c4" deleted # kubectl get pod NAME READY STATUS RESTARTS AGE nginx-disk-6d5659d745-nz2pv 1/1 Running 0 5s # kubectl exec nginx-disk-6d5659d745-nz2pv ls /data lost+found test