Using an SFS File System Through a Dynamic PV
This section describes how to use storage classes to dynamically create PVs and PVCs for data persistence and sharing in workloads.
Prerequisites
- You have created a cluster and installed the CCE Container Storage (Everest) add-on in the cluster.
- To create a cluster using commands, ensure kubectl is used. For details, see Accessing a Cluster Using kubectl.
Automatically Creating an SFS File System Through kubectl
- Use kubectl to access the cluster.
- Use StorageClass to dynamically create a PVC and PV.
- Create the pvc-sfs-auto.yaml file.apiVersion: v1kind: PersistentVolumeClaimmetadata:name: pvc-sfs-autonamespace: defaultannotations:everest.io/csi.volume-name-prefix: test # (Optional) Storage volume name prefix of the automatically created underlying storagespec:accessModes:- ReadWriteMany # The value must be ReadWriteMany for SFS.resources:requests:storage: 1Gi # SFS volume capacitystorageClassName: csi-nas # The StorageClass is SFS.
Table 1 Key parameters Parameter
Mandatory
Description
storage
Yes
Requested capacity in the PVC, in Gi.
For SFS, this parameter is used only for verification and cannot be empty or 0. Its value is fixed at 1, and any value set will not take effect for SFS file systems.
everest.io/csi.volume-name-prefix
No
(Optional) This parameter is available only when the cluster version is v1.23.14-r0, v1.25.9-r0, v1.27.6-r0, v1.28.4-r0, or later, and Everest of v2.4.15 or later is installed in the cluster.
This parameter specifies the name of the underlying storage that is automatically created. The actual underlying storage name is in the format of "Storage volume name prefix + PVC UID". If this parameter is left blank, the default prefix pvc will be used.
Enter 1 to 26 characters that cannot start or end with a hyphen (-). Only lowercase letters, digits, and hyphens (-) are allowed.
For example, if the storage volume name prefix is set to test, the actual underlying storage name is test-{UID}.
- Run the following command to create a PVC:kubectl apply -f pvc-sfs-auto.yaml
- Create the pvc-sfs-auto.yaml file.
- Create an application.
- Create a file named web-demo.yaml. In this example, the SFS volume is mounted to the /data path.apiVersion: apps/v1kind: Deploymentmetadata:name: web-demonamespace: defaultspec:replicas: 2selector:matchLabels:app: web-demotemplate:metadata:labels:app: web-demospec:containers:- name: container-1image: nginx:latestvolumeMounts:- name: pvc-sfs-volume # Volume name, which must be the same as the volume name in the volumes fieldmountPath: /data # Location where the storage volume is mountedimagePullSecrets:- name: default-secretvolumes:- name: pvc-sfs-volume # Volume name, which can be customizedpersistentVolumeClaim:claimName: pvc-sfs-auto # Name of the created PVC
- Run the following command to create a workload to which the SFS volume is mounted:kubectl apply -f web-demo.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 and Sharing.
- Create a file named web-demo.yaml. In this example, the SFS volume is mounted to the /data path.
Verifying Data Persistence and Sharing
- View the deployed application and files.
- Run the following command to view the created pod:kubectl get pod | grep web-demo
Expected output:
web-demo-846b489584-mjhm9 1/1 Running 0 46sweb-demo-846b489584-wvv5s 1/1 Running 0 46s - Run the following commands in sequence to view the files in the /data path of the pods:kubectl exec web-demo-846b489584-mjhm9 -- ls /datakubectl exec web-demo-846b489584-wvv5s -- ls /data
If no result is returned for both pods, no file exists in the /data path.
- 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 web-demo-846b489584-mjhm9 -- touch /data/static
- Run the following command to check the files in the /data path:kubectl exec web-demo-846b489584-mjhm9 -- ls /data
Expected output:
static - Verify data persistence.
- Run the following command to delete the pod named web-demo-846b489584-mjhm9:kubectl delete pod web-demo-846b489584-mjhm9
Expected output:
pod "web-demo-846b489584-mjhm9" deletedAfter the deletion, the Deployment controller automatically creates a replica.
- Run the following command to view the created pod:kubectl get pod | grep web-demo
The expected output is as follows, in which web-demo-846b489584-d4d4j is the newly created pod:
web-demo-846b489584-d4d4j 1/1 Running 0 110sweb-demo-846b489584-wvv5s 1/1 Running 0 7m50s - Run the following command to check whether the files in the /data path of the new pod have been modified:kubectl exec web-demo-846b489584-d4d4j -- ls /data
Expected output:
staticThe static file is retained, indicating that the data in the file system can be stored persistently.
- Run the following command to delete the pod named web-demo-846b489584-mjhm9:
- Verify data sharing.
- Run the following command to view the created pod:kubectl get pod | grep web-demo
Expected output:
web-demo-846b489584-d4d4j 1/1 Running 0 7mweb-demo-846b489584-wvv5s 1/1 Running 0 13m - Run the following command to create a file named share in the /data path of either pod: In this example, select the pod named web-demo-846b489584-d4d4j.kubectl exec web-demo-846b489584-d4d4j -- touch /data/share
Check the files in the /data path of the pod.
kubectl exec web-demo-846b489584-d4d4j -- ls /dataExpected output:
sharestatic - Check whether the share file exists in the /data path of another pod (web-demo-846b489584-wvv5s) as well to verify data sharing.kubectl exec web-demo-846b489584-wvv5s -- ls /data
Expected output:
sharestaticAfter you create a file in the /data path of a pod, if the file is also created in the /data path of the other pod, the two pods share the same volume.
- Run the following command to view the created pod:
Related Operations
You can also perform the operations listed in Table 2.
Operation | Description | Procedure |
---|---|---|
Viewing events | 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 | View, copy, or download the YAML file of a PVC or PV. |
|
- Prerequisites
- Automatically Creating an SFS File System Through kubectl
- Verifying Data Persistence and Sharing
- Related Operations