edit-icon download-icon

Use Alibaba Cloud cloud disks

Last Updated: Apr 25, 2018

You can use the Alibaba Cloud cloud disk storage volumes in Alibaba Cloud Container Service Kubernetes clusters.

Currently, Alibaba Cloud cloud disk provides the following two Kubernetes mount methods:

Static storage volumes

You can use Alibaba Cloud cloud disk storage volumes by using the volume method or PV/PVC.

Prerequisites

Before using cloud disk data volumes, you must create cloud disks in the Elastic Compute Service (ECS) console. For how to create cloud disks, see Create a cloud disk.

Instructions

  • The cloud disk is not a shared storage and can only be mounted by one pod at the same time.
  • Apply for a cloud disk and obtain the disk ID before using cloud disk storage volumes. For more information, see Create a cloud disk.
  • volumeId: The disk ID of the mounted cloud disk, which must be the same as volumeName and PV Name.
  • Only the cluster node that is in the same zone as the cloud disk can mount the cloud disk.

Use volume method

Use the disk-deploy.yaml file to create the pod.

  1. apiVersion: extensions/v1beta1
  2. kind: Deployment
  3. metadata:
  4. name: nginx-disk-deploy
  5. spec:
  6. replicas: 1
  7. template:
  8. metadata:
  9. labels:
  10. app: nginx
  11. spec:
  12. containers:
  13. - name: nginx-flexvolume-disk
  14. image: nginx
  15. volumeMounts:
  16. - name: "d-bp1j17ifxfasvts3tf40"
  17. mountPath: "/data"
  18. volumes:
  19. - name: "d-bp1j17ifxfasvts3tf40"
  20. flexVolume:
  21. driver: "alicloud/disk"
  22. fsType: "ext4"
  23. options:
  24. volumeId: "d-bp1j17ifxfasvts3tf40"

Use PV/PVC

Step 1 Create cloud disk type PV

You can create the cloud disk type PV in the Container Service console or by using the YAML file.

Create PV by using YAML file

Use the disk-pv.yaml file to create the PV.

Note: The pv name must be the same as the Alibaba Cloud cloud disk ID.

  1. apiVersion: v1
  2. kind: PersistentVolume
  3. metadata:
  4. name: d-bp1j17ifxfasvts3tf40
  5. spec:
  6. capacity:
  7. storage: 20Gi
  8. storageClassName: disk
  9. accessModes:
  10. - ReadWriteOnce
  11. flexVolume:
  12. driver: "alicloud/disk"
  13. fsType: "ext4"
  14. options:
  15. volumeId: "d-bp1j17ifxfasvts3tf40"

Create cloud disk data volumes in Container Service console

  1. Log on to the Container Service console.

  2. Click Kubernetes > Clusters > Storage in the left-side navigation pane.

  3. Select the cluster from the Clusters drop-down list and then click Create in the upper-right corner.

    1

  4. The Create Data Volume dialog box appears. Configure the data volume parameters.

    • Type: Select Cloud Disk in this example.
    • Name: Enter the name of the data volume you are about to create. The data volume name must be the same as the Cloud Disk ID.
    • Capacity: Enter the capacity of the data volume to be created. Make sure the capacity cannot exceed the disk capacity.
    • Access Mode: ReadWriteOnce by default.
    • Cloud Disk ID: Select the cloud disk to be mounted and is in the same region and zone as the cluster.
    • File System Type: You can select the data type in which data is stored to the cloud disk. The supported types include ext4, ext3, xfs, and vfat. ext4 is selected by default.
    • Tag: Click Add Tag to add tags for this data volume.

    1

  5. Click Create after the configurations.

Step 2 Create PVC

Use the disk-pvc.yaml file to create the PVC.

  1. kind: PersistentVolumeClaim
  2. apiVersion: v1
  3. metadata:
  4. name: pvc-disk
  5. spec:
  6. storageClassName: disk
  7. accessModes:
  8. - ReadWriteOnce
  9. resources:
  10. requests:
  11. storage: 20Gi

Step 3 Create pod

Use the disk-pod.yaml file to create the pod.

  1. apiVersion: v1
  2. kind: Pod
  3. metadata:
  4. name: "flexvolume-alicloud-example"
  5. spec:
  6. containers:
  7. - name: "nginx"
  8. image: "nginx"
  9. volumeMounts:
  10. - name: pvc-disk
  11. mountPath: "/data"
  12. volumes:
  13. - name: pvc-disk
  14. persistentVolumeClaim:
  15. claimName: pvc-disk

Dynamic storage volumes

By using the cloud disk dynamic volumes, the cloud disk storage can be automatically created and mounted. Currently, three specifications (common, efficiency, and SSD) are supported, which correspond to alicloud-disk-common, alicloud-disk-efficiency, and alicloud-disk-ssd respectively.

Step 1 Create PVC

Use the following orchestration template to create the PVC:

  1. kind: PersistentVolumeClaim
  2. apiVersion: v1
  3. metadata:
  4. name: disk-common
  5. spec:
  6. accessModes:
  7. - ReadWriteOnce
  8. storageClassName: alicloud-disk-common
  9. resources:
  10. requests:
  11. storage: 20Gi

Step 2 Create pod

Use the following orchestration template to create the pod:

  1. kind: Pod
  2. apiVersion: v1
  3. metadata:
  4. name: disk-pod-common
  5. spec:
  6. containers:
  7. - name: disk-pod
  8. image: nginx
  9. volumeMounts:
  10. - name: disk-pvc
  11. mountPath: "/mnt"
  12. restartPolicy: "Never"
  13. volumes:
  14. - name: disk-pvc
  15. persistentVolumeClaim:
  16. claimName: disk-common
Thank you! We've received your feedback.