Dynamically Mounting an EVS Disk to a StatefulSet
Application Scenarios
Dynamic mounting is available only for creating a StatefulSet. It is implemented through a volume claim template (volumeClaimTemplates field) and depends on the storage class to dynamically provision PVs. In this mode, each pod in a multi-pod StatefulSet is associated with a unique PVC and PV. After a pod is rescheduled, the original data can still be mounted to it based on the PVC name. In the common mounting mode for a Deployment, if ReadWriteMany is supported, multiple pods of the Deployment will be mounted to the same underlying storage.
Prerequisites
- You have created a cluster and installed the CSI add-on (everest) in the cluster.
- If you want to create a cluster using commands, use kubectl to connect to the cluster. For details, see Connecting to a Cluster Using kubectl.
(Console) Dynamically Mounting an EVS Disk
- Log in to the CCE console and click the cluster name to access the cluster console.
- In the navigation pane on the left, click Workloads. In the right pane, click the StatefulSets tab.
- Click Create Workload in the upper right corner. On the displayed page, click Data Storage in the Container Settings area and click Add Volume to select VolumeClaimTemplate (VTC).
- Click Create PVC. In the dialog box displayed, configure the PVC parameters.
Click Create.
Parameter
Description
PVC Type
In this example, select EVS.
PVC Name
Enter the name of the PVC. After a PVC is created, a suffix is automatically added based on the number of pods. The format is <Custom PVC name>-<Serial number>, for example, example-0.
Creation Method
You can select Dynamically provision to create a PVC, PV, and underlying storage on the console in cascading mode.
Storage Classes
The storage class for EVS disks is csi-disk.
AZ
Select the AZ of the EVS disk. The AZ must be the same as that of the cluster node.
NOTE:An EVS disk can only be mounted to a node in the same AZ. After an EVS disk is created, its AZ cannot be changed.
Disk Type
Select an EVS disk type.
Access Mode
EVS disks support only ReadWriteOnce, indicating that a storage volume can be mounted to one node in read/write mode. For details, see Volume Access Modes.
Capacity (GiB)
Capacity of the requested storage volume.
Encryption
You can select Encryption and an encryption key to encrypt underlying storage. Only EVS disks and SFS file systems support encryption.
Enterprise Project
Supported enterprise projects: default, the one to which the cluster belongs, or the one specified by the storage class.
- Enter the path to which the volume is mounted.
Table 1 Mounting a storage volume Parameter
Description
Mount Path
Enter a mount path, for example, /tmp.
This parameter indicates the container path to which a data volume will be mounted. Do not mount the volume to a system directory such as / or /var/run. Otherwise, errors will occur in containers. Mount the volume to an empty directory. If the directory is not empty, ensure that there are no files that affect container startup. Otherwise, the files will be replaced, causing container startup failures or workload creation failures.NOTICE:If a volume is mounted to a high-risk directory, use an account with minimum permissions to start the container. Otherwise, high-risk files on the host machine may be damaged.
Subpath
Enter a subpath, for example, tmp, indicating that data in the mount path of the container will be stored in the tmp folder of the volume.
A subpath is used to mount a local volume so that the same data volume is used in a single pod. If this parameter is left blank, the root path is used by default.
Permission
- Read-only: You can only read the data in the mounted volumes.
- Read/Write: You can modify the data volumes mounted to the path. Newly written data is not migrated if the container is migrated, which may cause data loss.
In this example, the disk is mounted to the /data path of the container. The container data generated in this path is stored in the EVS disk.
- Dynamically mount and use storage volumes. For details about other parameters, see Creating a StatefulSet. After the configuration, click Create Workload.
After the workload is created, the data in the container mount directory will be persistently stored. Verify the storage by referring to Verifying Data Persistence.
(kubectl) Using an Existing EVS Disk
- Use kubectl to connect to the cluster.
- Create a file named statefulset-evs.yaml. In this example, the EVS volume is mounted to the /data path.
apiVersion: apps/v1 kind: StatefulSet metadata: name: statefulset-evs namespace: default spec: selector: matchLabels: app: statefulset-evs template: metadata: labels: app: statefulset-evs spec: containers: - name: container-1 image: nginx:latest volumeMounts: - name: pvc-disk # The value must be the same as that in the volumeClaimTemplates field. mountPath: /data # Location where the storage volume is mounted. imagePullSecrets: - name: default-secret serviceName: statefulset-evs # Headless Service name. replicas: 2 volumeClaimTemplates: - apiVersion: v1 kind: PersistentVolumeClaim metadata: name: pvc-disk namespace: default annotations: everest.io/disk-volume-type: SAS # EVS disk type. everest.io/crypt-key-id: <your_key_id> # (Optional) Encryption key ID. Mandatory for an encrypted disk. everest.io/enterprise-project-id: <your_project_id> # (Optional) Enterprise project ID. If an enterprise project is specified, use the same enterprise project when creating a PVC. Otherwise, the PVC cannot be bound to a PV. labels: failure-domain.beta.kubernetes.io/region: <your_region> # Region of the node where the application is to be deployed. failure-domain.beta.kubernetes.io/zone: <your_zone> # AZ of the node where the application is to be deployed. spec: accessModes: - ReadWriteOnce # The value must be ReadWriteOnce for EVS disks. resources: requests: storage: 10Gi # EVS disk capacity, ranging from 1 to 32768. storageClassName: csi-disk # Storage class type for EVS disks. --- apiVersion: v1 kind: Service metadata: name: statefulset-evs # Headless Service name. namespace: default labels: app: statefulset-evs spec: selector: app: statefulset-evs clusterIP: None ports: - name: statefulset-evs targetPort: 80 nodePort: 0 port: 80 protocol: TCP type: ClusterIP
Table 2 Key parameters Parameter
Mandatory
Description
failure-domain.beta.kubernetes.io/region
Yes
Region where the cluster is located.
For details about the value of region, see Regions and Endpoints.
failure-domain.beta.kubernetes.io/zone
Yes
AZ where the EVS volume is created. It must be the same as the AZ planned for the workload.
For details about the value of zone, see Regions and Endpoints.
everest.io/disk-volume-type
Yes
EVS disk type. All letters are in uppercase.- SATA: common I/O
- SAS: high I/O
- SSD: ultra-high I/O
everest.io/crypt-key-id
No
Mandatory when the EVS disk is encrypted. Enter the encryption key ID selected during EVS disk creation.
To obtain the encryption key ID, log in to the Cloud Server Console. In the navigation pane, choose Elastic Volume Service > Disks. Click the name of the target EVS disk to go to its details page. On the Summary tab page, copy the value of KMS Key ID in the Configuration Information area.
everest.io/enterprise-project-id
No
Optional.
Enterprise project ID of the EVS disk. If an enterprise project is specified, specify the same enterprise project when creating a PVC. Otherwise, the PVC cannot be bound to a PV.
To obtain the enterprise project ID, log in to the Cloud Server Console. In the navigation pane, choose Elastic Volume Service > Disks. Click the name of the target EVS disk to go to its details page. On the Summary tab page, click the enterprise project in Management Information to access the enterprise project console. Copy the corresponding ID to obtain the ID of the enterprise project to which the EVS disk belongs.
storage
Yes
Requested PVC capacity, in Gi. The value ranges from 1 to 32768.
storageClassName
Yes
The storage class name for EVS disks is csi-disk.
- Run the following command to create a workload to which the EVS volume is mounted:
kubectl apply -f statefulset-evs.yaml
After the workload is created, the data in the container mount directory will be persistently stored. Verify the storage by referring to Verifying Data Persistence.
Verifying Data Persistence
- View the deployed application and EVS volume files.
- Run the following command to view the created pod:
kubectl get pod | grep statefulset-evs
Expected output:statefulset-evs-0 1/1 Running 0 45s statefulset-evs-1 1/1 Running 0 28s
- Run the following command to check whether the EVS volume has been mounted to the /data path:
kubectl exec statefulset-evs-0 -- df | grep data
Expected output:
/dev/sdd 10255636 36888 10202364 0% /data
- Run the following command to view the files in the /data path:
kubectl exec statefulset-evs-0 -- ls /data
Expected output:
lost+found
- Run the following command to view the created pod:
- Run the following command to create a file named static in the /data path:
kubectl exec statefulset-evs-0 -- touch /data/static
- Run the following command to view the files in the /data path:
kubectl exec statefulset-evs-0 -- ls /data
Expected output:
lost+found static
- Run the following command to delete the pod named web-evs-auto-0:
kubectl delete pod statefulset-evs-0
Expected output:
pod "statefulset-evs-0" deleted
- After the deletion, the StatefulSet controller automatically creates a replica with the same name. Run the following command to check whether the files in the /data path have been modified:
kubectl exec statefulset-evs-0 -- ls /data
Expected output:
lost+found static
If the static file still exists, the data in the EVS volume can be stored persistently.
Related Operations
Operation |
Description |
Procedure |
---|---|---|
Expanding the capacity of an EVS disk |
Quickly expand the capacity of a mounted EVS disk on the CCE console. |
|
Viewing events |
You can view event names, event types, number of occurrences, Kubernetes events, first occurrence time, and last occurrence time of the PVC or PV. |
|
Viewing a YAML file |
You can view, copy, and download the YAML files of a PVC or PV. |
|
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot