This topic describes how to use a pre-existing cloud disk as a statically provisioned volume. This process involves manually creating a PersistentVolume (PV) that references the disk, binding it to a PersistentVolumeClaim (PVC), and then mounting it in a pod.
Prerequisites
To use a cloud disk volume, create a cloud disk in the ECS console. For more information, see Create an empty data disk.
Use a cloud disk volume with PV and PVC
-
Create a cloud disk PV.
You can create the PV by using a YAML manifest or in the ACK console.
-
Create a PV by using a YAML manifest.
-
Create a file named disk-pv.yaml with 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 Alibaba Cloud disk ID (volumeId). -
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 View Details in the Actions column.
-
In the left-side navigation pane, choose .
-
On the Persistent Volumes page, click Create in the upper-right corner.
-
In the Create PV dialog box, set the following parameters.
Parameter
Description
PV Type
Select cloud disk.
Volume Plug-in
Select Flexvolume.
Access Mode
Defaults to ReadWriteOnce.
Disk ID:
Select an Available cloud disk in the same region and zone as the cluster.
File System Type:
Select the file system type. Valid values are ext4, ext3, xfs, and vfat. The default is ext4.
Labels
Add labels to the volume.
-
After configuring the parameters, click Create.
-
-
-
Create a PVC.
-
Create a file named disk-pvc.yaml with the following content.
kind: PersistentVolumeClaim apiVersion: v1 metadata: name: pvc-disk spec: accessModes: - ReadWriteOnce storageClassName: disk resources: requests: storage: 20Gi -
Run the following command to create the PVC.
kubectl apply -f disk-pvc.yaml
-
-
Create a pod.
-
Create a file named disk-pod.yaml with 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-disk -
Run the following command to create the pod.
kubectl apply -f disk-pod.yaml
-