Use a static cloud disk persistent volume
Mount an existing cloud disk with a persistent volume (PV) and persistent volume claim (PVC).
Static provisioning uses an existing Elastic Compute Service (ECS) cloud disk. ACK binds it to a PVC without creating a disk. For automatic disk creation, see the dynamic provisioning documentation.
Prerequisites
Required:
-
ACK cluster
-
Cloud disk is created in ECS.
Considerations
-
Cloud disk is in the same region and zone as the cluster.
-
PV
namematches the disk ID involumeId.
Mount a disk with a PV and PVC
Step 1: Create a PersistentVolume
Create a PV from a YAML file or in the ACK console.
Option 1: YAML file
-
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****"Replace these values:
Field Description nameDisk ID. Must match volumeId.failure-domain.beta.kubernetes.io/zoneZone of the cluster and disk, for example, cn-hangzhou-b.failure-domain.beta.kubernetes.io/regionRegion of the cluster and disk, for example, cn-hangzhou.capacity.storageDisk size, for example, 20Gi.volumeIdDisk ID. Must match name. -
Apply the YAML:
kubectl apply -f disk-pv.yaml -
Verify PV creation:
kubectl get pvExpected output:
NAME CAPACITY ACCESS MODES STATUS CLAIM STORAGECLASS AGE d-bp1j17ifxfasvts3**** 20Gi RWO Available disk 5sSTATUSAvailablemeans the PV is ready to claim.
Option 2: ACK console
-
Log on to the ACK console.
-
On Clusters, click Details for your cluster in the Actions column.
-
In the left-side navigation pane, choose Volumes > Persistent Volumes.
-
Click Create.
-
In Create PV, configure:
Parameter Description PV Type Select Cloud Disk. Volume Plug-in Select Flexvolume. Access Mode Defaults to ReadWriteOnce. Disk ID Cloud disk in the same region and zone as the cluster. File System Type File system type. Valid values: ext4 (default), ext3, xfs, vfat. Label Optional PV labels. -
Click Create.
Step 2: Create a PersistentVolumeClaim
-
Create a file named
disk-pvc.yamlwith the following content:storageClassNameandaccessModesmust match the PV. Kubernetes binds the PVC when both match.kind: PersistentVolumeClaim apiVersion: v1 metadata: name: pvc-disk spec: accessModes: - ReadWriteOnce storageClassName: disk resources: requests: storage: 20Gi -
Apply the YAML:
kubectl apply -f disk-pvc.yaml -
Verify PVC binding:
kubectl get pvcExpected output:
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS AGE pvc-disk Bound d-bp1j17ifxfasvts3**** 20Gi RWO disk 5sSTATUSBoundconfirms PVC-PV binding.
Step 3: Create a pod that uses the PVC
-
Create a file named
disk-pod.yamlwith the following content: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-diskThe StatefulSet mounts the PVC (
claimName: pvc-disk) at/datain the container. -
Apply the YAML:
kubectl apply -f disk-pod.yaml -
Verify the pod runs with the volume mounted:
kubectl get podsExpected output:
NAME READY STATUS RESTARTS AGE web-0 1/1 Running 0 10sSTATUSRunningconfirms the pod started with the disk at/data.
Next steps
-
See the dynamic provisioning documentation to let ACK provision disks automatically.
-
See the snapshot documentation to configure disk snapshots for backup and recovery.