This topic describes how to mount a statically provisioned disk volume by using a
persistent volume (PV) and a persistent volume claim (PVC).
Prerequisites
To mount a disk as a volume, you must first create the disk in the Elastic Compute
Service (ECS) console. For more information, see
Create a disk.
Note Your disk must meet the following requirements:
- An ultra disk must have a minimum capacity of 20 GiB.
- A standard SSD must have a minimum capacity of 20 GiB.
- An enhanced SSD (ESSD) must have a minimum capacity of 20 GiB.
Mount a statically provisioned disk volume by using a PV and a PVC
- Create a PV of the disk type.
You can create a PV of the disk type in the Container Service for Kubernetes (ACK)
console or by using a YAML file.
- Create a PV by using a YAML file.
- Create a file named disk-pv.yaml by using the following template:
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****"
Note The name
of the PV must be the same as the disk ID that is specified by volumeId
.
- Run the following command to create a PV:
kubectl apply -f disk-pv.yaml
- Create a PV in the ACK console.
- Log on to the ACK console.
- In the left-side navigation pane of the ACK console, click Clusters.
- On the Clusters page, find the cluster that you want to manage and click the name or click Details in the Actions column.
- In the left-side navigation pane of the details page, choose .
- In the upper-right corner of the Persistent Volumes page, click Create.
- In the Create PV dialog box, set the parameters.
Parameter |
Description |
PV Type |
In this example, Cloud Disk is selected.
|
Volume Plug-in |
In this example, Flexvolume is selected.
|
Access Mode |
By default, this parameter is set to ReadWriteOnce. |
Disk ID |
Select a mountable disk that is deployed in the same region and zone as your cluster.
|
File System Type |
Select the file system type of the disk. Valid values: ext4, ext3, xfs, and vfat. Default value: ext4.
|
Label |
Add labels to the PV. |
- After you complete the settings, click Create.
- Create a PVC.
- Create a file named disk-pvc.yaml by using the following template:
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: pvc-disk
spec:
accessModes:
- ReadWriteOnce
storageClassName: disk
resources:
requests:
storage: 20Gi
- Run the following command to create a PVC:
kubectl apply -f disk-pvc.yaml
- Create a pod.
- Create a file named disk-pod.yaml by using the following template:
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 a pod:
kubectl apply -f disk-pod.yaml