Skip to Content
Cluster StorageBlock StorageUsing UDISK in UK8S

Using UDISK in UK8S

UK8S supports the direct use of UDisk as a persistent volume in the cluster.

Note:

  1. All cloud hosts support SSD/SATA UDisk, if the type of the cloud host node is fast, RSSD UDisk is also supported;

  2. The minimum value of SSD/SATA UDisk is 1GB, the maximum is 8000GB, and the maximum of RSSD UDisk is 32000GB;

  3. UDisk and the cloud host must be located in the same availability zone. If your cluster is in cross-availability zone mode, please pay attention when deploying applications.

  4. RSSD cloud drives have additional restrictions, please see Use RSSD UDisk in UK8S.

1. Storage Class StorageClass

Before creating a persistent storage volume (PersistentVolume), you need to first create a StorageClass, and then use StorageClassName in PVC.

The UK8S cluster creates three StorageClasses by default. You can also create a new StorageClass. Here is an example and explanation:

apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: udisk-ssd-test provisioner: udisk.csi.ucloud.cn #Storage provider, remain unchanged here. parameters: type: "ssd" # Storage media, supports ssd, rssd, and sata, required fsType: "ext4" # File system, required udataArkMode: "no" # Whether to enable Ark mode, not enabled by default, optional chargeType: "month" # Payment type, supports dynamic, month, year, default is by the hour if not filled. quantity: "1" # Purchase duration, no need to fill in for dynamic, can purchase 1-9 months, or 1-10 years reclaimPolicy: Delete # PV recycling policy, supports Delete and Retain, defaulted to Delete, optional volumeBindingMode: WaitForFirstConsumer # Highly recommended to configuring this parameter allowVolumeExpansion: true # Declares that this storage class supports the expansion feature mountOptions: - debug - rw

Note: For Kubernetes versions prior to 1.15, mountOptions can’t be used normally, please don’t fill in. see Issue80191 

2. Create PersistentVolumeClaim PVC

2.1 New UDisk

If you are using a new UDisk, you can directly create a PVC object, and CSI will automatically create a UDisk and associate it. If volumeBindingMode  in storageClass is set to WaitForFirstConsumer, you need to wait for the Pod to use the PVC before creating the real UDisk.

kind: PersistentVolumeClaim apiVersion: v1 metadata: name: test-pvc-claim spec: accessModes: - ReadWriteOnce ## storageClassName must be consistent with the name of the StorageClass created above storageClassName: udisk-ssd-test resources: requests: storage: 20Gi

2.2 Use Existing UDisk

If you need to use an existing UDisk, you need to create a PV object first and bind it with the existing UDisk, and then create a PVC object and associate it with the same claim as the PV

Create PersistentVolume PV

apiVersion: v1 kind: PersistentVolume metadata: name: test-pvc-claim spec: accessModes: - ReadWriteOnce capacity: storage: 20Gi csi: driver: udisk.csi.ucloud.cn volumeAttributes: type: ssd # Disk type, enumeration ssd,sata,rssd volumeHandle: bs-qg55w254 # Please modify to your own UDiskId # nodeAffinity: It is highly recommended to add this field persistentVolumeReclaimPolicy: Retain # storageClassName must be consistent with the name of the StorageClass created above storageClassName: udisk-ssd-test

Note: According to the Pod scheduling policy using UDisk, in order to ensure that the subsequent scheduling can be successfully executed, it is strongly recommended to add a nodeAffinity field when creating a PV. As different versions and different Storage Classes can vary, you can refer to the corresponding fields of the PV created by the same Storage Class CSI.

2.3 Create PVC and Associate with PV

spec.storageClassName, spec.resources.requests.storage, and volumeName need to correspond to PV.

kind: PersistentVolumeClaim apiVersion: v1 metadata: name: test-pvc-claim spec: accessModes: - ReadWriteOnce storageClassName: udisk-ssd-test resources: requests: storage: 20Gi volumeName: test-pvc-claim

3. Use PVC in Pod

apiVersion: v1 kind: Pod metadata: name: nginx spec: containers: - name: nginx image: uhub.surfercloud.com/ucloud/nginx:latest volumeMounts: - name: test mountPath: /data ports: - containerPort: 80 volumes: - name: test persistentVolumeClaim: claimName: test-pvc-claim

4. Use StatefulSet

If you need to deploy multi-replica stateful applications, we recommend using StatefulSet instead of Deployment, because multiple pods in Deployment will share the same disk, which will cause issues if the pods are on different nodes. StatefulSet allows multiple pods to use their own disks.

Generally, StatefulSet is used to dynamically create pvc and udisk disks for each pod. The following yaml can be used as a reference:

apiVersion: apps/v1 kind: StatefulSet metadata: name: web spec: selector: matchLabels: app: nginx serviceName: "nginx" replicas: 4 template: metadata: labels: app: nginx spec: terminationGracePeriodSeconds: 10 containers: - name: nginx image: uhub.surfercloud.com/ucloud/nginx:latest ports: - containerPort: 80 name: web volumeMounts: - name: www # The directory where the cloud disk is mounted mountPath: /usr/share/nginx/html volumeClaimTemplates: - metadata: name: www spec: accessModes: [ "ReadWriteOnce" ] # The StorageClass to use, indicating what type of disk to create storageClassName: "udisk-ssd-test" resources: requests: storage: 20Gi