Container Service for Kubernetes (ACK) lets you mount and use Container Network File System (CNFS) as shared NAS volumes. You can use CNFS to mount the same directory of a NAS file system to multiple applications or pods. This resolves data sharing issues among pods. This topic describes how to use CNFS to manage a shared NAS volume using a StatefulSet application as an example.
Prerequisites
NAS is activated.
If this is the first time you visit the product page of NAS, follow the on-screen instructions to activate the NAS service.
A Container Service for Kubernetes (ACK) cluster that runs Kubernetes 1.20 or later is created. The Container Storage Interface (CSI) plug-in is used as the volume plug-in. For more information, see Create an ACK managed cluster.
The versions of csi-plugin and csi-provisioner are v1.24.11-5221f79-aliyun or later. For more information about how to update csi-plugin and csi-provisioner, see Install and update the CSI components.
The version of storage-operator is v1.24.105-825188d-aliyun or later. For more information about how to update storage-operator, see Manage components.
A kubectl client is connected to your cluster. For more information, see Get a cluster kubeconfig and connect to the cluster using kubectl.
NoteFor more information about CNFS, see CNFS.
For more information about how to use CNFS to manage NAS file systems, see Use CNFS to manage NAS file systems (recommended).
Step 1: Create a workload for a shared volume
Create a persistent volume (PV) named
cnfs-nas-static-pv. The PV must reference a CNFS object namedcnfs-nas-filesystem, which represents your existing NAS file system.Create a persistent volume claim (PVC) named
cnfs-nas-static-pvcand bind it to the PV.Create a StatefulSet named
cnfs-nas-static-sts. In the StatefulSet, use a busybox image to mount the PVC and write a 1 GB temporary file named1G.tmpfileto the mount target.
Step 2: View the mount status
Run the following command to view the mount status.
kubectl exec cnfs-nas-static-sts-0 -- mount |grep nfsExpected output:
971134b0e8-****.cn-zhangjiakou.nas.aliyuncs.com:/ on /data type nfs (rw,nosuid,nodev,relatime,user_id=0,group_id=0,default_permissions,allow_other)The expected output shows a mount target. This indicates that the volume is mounted successfully.
Step 3: Check whether the persistent data is written successfully
Run the following command to write a 1 GB temporary file.
kubectl exec cnfs-nas-static-sts-0 -ti -- sh -c 'dd if=/dev/zero of=/data/1G.tmpfile bs=1G count=1;'Run the following command to verify that the 1 GB temporary file was created.
kubectl exec cnfs-nas-static-sts-0 -- ls -arlth /dataExpected output:
total 1G
-rw-r--r-- 1 root root 1.0G Dec 15 12:11 1G.tmpfileThe expected output indicates that the 1 GB temporary file 1G.tmpfile has been successfully written to the /data directory.
Step 4: Check whether the written data is shared in other pods
Run the following command to check whether the 1 GB temporary file is shared with the other pod, cnfs-nas-static-sts-1.
kubectl exec cnfs-nas-static-sts-1 -- ls -arlth /dataExpected output:
total 1G
-rw-r--r-- 1 root root 1.0G Dec 15 12:11 1G.tmpfileThe expected output indicates that the 1 GB temporary file 1G.tmpfile is shared between the pod cnfs-nas-static-sts-0 and the pod cnfs-nas-static-sts-1.
When you write data to shared storage from different pods, CNFS does not guarantee data consistency. To prevent file corruption, avoid writing to the same file from multiple pods.
References
To mount different directories in a NAS file system to different applications or pods for storage isolation, see Use CNFS to manage isolated NAS volumes (recommended).
To automatically scale out a NAS volume when its usage exceeds a specified threshold, see Use CNFS to automatically scale out NAS volumes.