Cloud Parallel File Storage (CPFS) is a high-throughput, high-IOPS parallel file system for high-performance computing (HPC) use cases such as AI training and autonomous driving. In an ACK cluster, multiple Pods can mount the same CPFS General-purpose Edition static volume to achieve high-performance data sharing and persistent storage.
How it works
The following workflow describes how to mount a CPFS General-purpose Edition static volume in an ACK cluster.
Create a Persistent Volume (PV): Register an existing CPFS General-purpose Edition file system in the cluster and declare its mount target, capacity, access mode, and other settings.
Create a Persistent Volume Claim (PVC): An application uses a PVC to request the registered storage resource. The PVC automatically binds to a matching PV.
Mount the volume in an application: Mount the bound PVC to an application Pod as a persistent directory in the container.
Prerequisites
Check and upgrade the CSI add-ons: Ensure that the csi-plugin and csi-provisioner add-ons are version v1.22.11-abbb810e-aliyun or later.
For upgrade instructions, see Upgrade CSI components.
Configure the storage add-on to support CPFS mounting.
Prepare a CPFS General-purpose Edition file system, a Protocol Service, and a mount target that the ACK cluster can mount.
If you have not created these resources, in the region where the cluster is deployed, create a CPFS General-purpose Edition file system. Use the VPC and vSwitch of the cluster to create a Protocol Service, and then generate a mount target.
File system: The file system must be in the same region as the cluster, run version 2.3.0 or later, and be deployed in a region where CPFS General-purpose Edition is available.
In the NAS console, on the File System List page, click the target CPFS file system. On the Basic Information page, verify the CPFS version.
Protocol Service: CPFS does not support cross-VPC mounting. The VPC that you use must be the same as the VPC of the cluster.
Obtain the mount target of the Protocol Service, which consists of a mount target domain name and an export directory. If you specify the export directory
/, the mount target iscpfs-****.<Region ID>.cpfs.aliyuncs.com:/share.On the Protocol Service page, click Export Directory, and then copy and save the mount target from the Mount address column.
Understand the Limits for CPFS General-purpose Edition.
Step 1: Create a PV
Create a PV in the cluster to register an existing CPFS file system.
Save the following content as cpfs-pv.yaml.
apiVersion: v1 kind: PersistentVolume metadata: name: cpfs-pv labels: # Define labels for subsequent PVC binding alicloud-pvname: cpfs-pv spec: accessModes: # Access mode - ReadWriteMany capacity: storage: 20Gi # Define the total capacity of the PV csi: driver: nasplugin.csi.alibabacloud.com # Use this fixed value volumeAttributes: mountProtocol: cpfs-nfs # Use the NFS protocol to mount CPFS path: "/share" # The mount directory in the mount target volumeAs: subpath # Subdirectory server: "cpfs-******-******.cn-shanghai.cpfs.aliyuncs.com" # The mount target domain name in the mount target volumeHandle: cpfs-pv # The unique identifier (UID) of the volume, which must match metadata.name mountOptions: # NFS mount options - rsize=1048576,wsize=1048576,hard,timeo=600,retrans=2,noresvport - vers=3Key parameters:
Parameter
Description
accessModesThe access mode of the PV.
capacity.storageThe declared volume capacity.
csi.driverThe driver type. For CPFS General-purpose Edition, this value is fixed as
nasplugin.csi.alibabacloud.com.csi.volumeAttributes.serverThe mount target domain name in the mount target of the CPFS General-purpose Edition Protocol Service export directory.
csi.volumeAttributes.pathThe mount directory in the mount target of the CPFS General-purpose Edition Protocol Service export directory, for example,
/share. You can set a subdirectory, for example,/share/dir.csi.volumeAttributes.mountProtocolcpfs-nfsindicates that CPFS is mounted by using the NFS protocol.csi.volumeAttributes.volumeAssubpathindicates that a subdirectory-type PV is created.csi.volumeHandleThe value must match the PV name.
Run the following command to create the PV.
kubectl apply -f cpfs-pv.yamlView the PV status.
kubectl get pv cpfs-pvExpected output:
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS REASON AGE cpfs-pv 20Gi RWX Retain Available 2s
Step 2: Create a PVC
Create a PVC to request the storage resource registered in the preceding step.
Save the following content as cpfs-pvc.yaml.
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: cpfs-pvc spec: accessModes: - ReadWriteMany # Access mode resources: requests: storage: 20Gi # Requested storage capacity selector: # matchLabels: alicloud-pvname: cpfs-pv # Bind exactly to the previously created PVParameter
Description
accessModesThe access mode that the PVC requests from the PV.
selectorBinds to the PV by matching its label.
resources.requests.storageThe storage capacity allocated to the Pod. The value must not exceed the PV capacity.
Create the PVC.
kubectl apply -f cpfs-pvc.yamlView the PVC status and verify that the PVC is bound to the PV.
kubectl get pvc cpfs-pvcExample output:
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS VOLUMEATTRIBUTESCLASS AGE cpfs-pvc Bound cpfs-pv 20Gi RWO <unset> 18m
Step 3: Create an application and mount the volume
Create an application workload and declare the previously created PVC in its configuration.
Save the following content as cpfs-test.yaml.
apiVersion: apps/v1 kind: StatefulSet metadata: name: cpfs-sts spec: selector: matchLabels: app: nginx serviceName: "nginx" replicas: 2 template: metadata: labels: app: nginx spec: containers: - name: nginx image: anolis-registry.cn-zhangjiakou.cr.aliyuncs.com/openanolis/nginx:1.14.1-8.6 volumeMounts: - name: cpfs-pvc mountPath: /data # Mount the volume to the /data directory in the container volumes: - name: cpfs-pvc persistentVolumeClaim: claimName: cpfs-pvc # Reference the previously created PVCCreate the StatefulSet.
kubectl apply -f cpfs-test.yamlView the Pod status.
kubectl get pods -l app=nginxExpected output:
NAME READY STATUS RESTARTS AGE cpfs-sts-0 1/1 Running 0 58s cpfs-sts-1 1/1 Running 0 50sCheck the mount point in the container to verify that CPFS is mounted.
kubectl exec cpfs-sts-0 -- mount | grep /dataThe following output indicates that the CPFS General-purpose Edition static volume is mounted.
cpfs-******-******.cn-shanghai.cpfs.aliyuncs.com:/share on /data type nfs (rw,relatime,vers=3,rsize=1048576,wsize=1048576,namlen=255,hard,nolock,noresvport,proto=tcp,port=30000,timeo=600,retrans=2,sec=sys,mountaddr=127.0.1.255,mountvers=3,mountport=30000,mountproto=tcp,local_lock=all,addr=127.0.1.255)
Verify shared storage and persistent storage
After the application is deployed, verify that the volume works as expected.
Shared storage
Create a file in one Pod and view it in another Pod to verify that the data is shared.
View the Pod information to obtain the Pod names.
kubectl get pod -l app=nginxExpected output:
NAME READY STATUS RESTARTS AGE cpfs-sts-0 1/1 Running 0 10s cpfs-sts-1 1/1 Running 0 5sCreate a file in one Pod.
Use the Pod named
cpfs-sts-0as an example:kubectl exec cpfs-sts-0 -- touch /data/test.txtCheck whether the file exists in another Pod.
Use the Pod named
cpfs-sts-1as an example.kubectl exec cpfs-sts-1 -- ls /dataExpected output:
test.txtThe file created earlier is displayed, which indicates that data can be shared among multiple Pods.
Persistent storage
Recreate the Deployment and check whether the data in the file system exists in the new Pod to verify persistent storage.
Delete the application Pod to trigger a rebuild.
kubectl rollout restart sts cpfs-stsView the Pods and wait for the new Pods to start and enter the Running state.
kubectl get pod -l app=nginxExpected output:
NAME READY STATUS RESTARTS AGE cpfs-sts-0 1/1 Running 0 1s cpfs-sts-1 1/1 Running 0 10sCheck whether the file created earlier exists in the new Pod.
Use the Pod named
cpfs-sts-0as an example.kubectl exec cpfs-sts-0 -- ls /dataExpected output:
test.txtThe file written earlier is displayed, which indicates that data is stored persistently.
Recommendations for production environments
Performance tuning: CPFS is suitable for high-throughput, high-IOPS workloads. Adjust the NFS mount parameters in the PV
mountOptionsfield, such asrsizeandwsize, to optimize performance and meet specific workload requirements.Data consistency: As shared storage, CPFS does not guarantee data consistency when multiple Pods write to the same file concurrently. To prevent file corruption, implement distributed locks at the application layer or use an append-only write pattern.
Volume management: Static volumes require you to manage PVs manually. If you need to automatically create and isolate volumes for multiple applications, use CNFS to manage CPFS dynamic volumes. For more information, see Manage General-purpose CPFS dynamic volumes.