Use a static cloud disk volume
Use a pre-existing cloud disk as a statically provisioned volume for your workloads. Create a PersistentVolume (PV) for the cloud disk manually, bind the PV to a PersistentVolumeClaim (PVC), and then mount the volume in a pod.
Prerequisites
Create an empty data disk in the Elastic Compute Service (ECS) console. For more information, see Create an empty data disk.
The cloud disk must reside in the same region and zone as the cluster and must be in the Available state.
Use a cloud disk volume with PV and PVC
Create a cloud disk PV.
Create a cloud disk PV by using a YAML manifest or in the Container Service for Kubernetes (ACK) console.
Create a PV by using a YAML manifest.
Create a file named
disk-pv.yamlwith the following content:apiVersion: v1 kind: PersistentVolume metadata: name: d-bp1j17ifxfasvts3**** labels: failure-domain.beta.kubernetes.io/zone: cn-hangzhou-b failure-domain.beta.kubernetes.io/region: cn-hangzhou spec: capacity: storage: 20Gi storageClassName: disk accessModes: - ReadWriteOnce flexVolume: driver: "alicloud/disk" fsType: "ext4" options: volumeId: "d-bp1j17ifxfasvts3****"NoteThe PV name (
name) must be the same as the cloud disk ID (volumeId). Replace the other example values with the values of your cloud disk.Run the following command to create the PV.
kubectl apply -f disk-pv.yaml
Create a PV in the ACK console.
Log on to the ACK console. In the left navigation pane, click Clusters.
On the Clusters page, click the name of the destination cluster or click Details in the Actions column.
In the left-side navigation pane, choose Volumes > Persistent Volumes.
On the Persistent Volumes page, click Create in the upper-right corner.
In the Create PV dialog box, configure the parameters of the volume.
Parameter
Description
PV Type
In this example, select cloud disk.
Volume Plug-in
In this example, select Flexvolume.
Access Mode
The default value is ReadWriteOnce.
Disk ID:
Select the cloud disk that you prepared.
File System Type:
Select the file system type. Valid values are ext4, ext3, xfs, and vfat. The default value is ext4.
Labels
Add labels to the volume.
After you configure the parameters, click Create.
Create a PVC.
Create a file named
disk-pvc.yamlwith the following content:kind: PersistentVolumeClaim apiVersion: v1 metadata: name: pvc-disk spec: accessModes: - ReadWriteOnce storageClassName: disk resources: requests: storage: 20GiRun the following command to create the PVC.
kubectl apply -f disk-pvc.yaml
Create a pod by using a StatefulSet.
Create a file named
disk-pod.yamlwith the following content to define a Service and a StatefulSet that mounts thepvc-diskPVC at/data:apiVersion: v1 kind: Service metadata: name: nginx labels: app: nginx spec: ports: - port: 80 name: web clusterIP: None selector: app: nginx --- apiVersion: apps/v1 kind: StatefulSet metadata: name: web spec: selector: matchLabels: app: nginx serviceName: "nginx" template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx ports: - containerPort: 80 name: web volumeMounts: - name: pvc-disk mountPath: /data volumes: - name: pvc-disk persistentVolumeClaim: claimName: pvc-diskRun the following command to create the pod.
kubectl apply -f disk-pod.yaml