ACKCNFS can be mounted and used as a NAS shared storage volume. As illustrated by a StatefulSet application, CNFS enables mounting the same directory of a NAS file system across multiple applications or Pods to resolve data-sharing issues between Pods.
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 Connect to an ACK cluster using kubectl.
NoteFor more information about CNFS, see CNFS.
For more information about how to use CNFS to manage NAS file systems, see Manage NAS file systems using CNFS.
Step 1: Create a workload for a shared volume
-
Create a persistent volume (PV) named
cnfs-nas-static-pv. The PV references a CNFS namedcnfs-nas-filesystem, which is the NAS file system you have created. -
Create a persistent volume claim (PVC) named
cnfs-nas-static-pvcand bind the PV to the PVC. -
Create a StatefulSet named
cnfs-nas-static-sts. The StatefulSet uses a busybox image to mount the PVC and writes 1 GB of temporary data1G.tmpfileto the mount point.
Step 2: View the mount result
View the mount result:
kubectl exec cnfs-nas-static-sts-0 -- mount |grep nfs
Expected 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 point, which indicates that the volume is mounted.
Step 3: Check whether data is persisted to the volume
Write a temporary file that is 1 GB in size to the directory:
kubectl exec cnfs-nas-static-sts-0 -ti -- sh -c 'dd if=/dev/zero of=/data/1G.tmpfile bs=1G count=1;'
Check whether the temporary file is written to the directory:
kubectl exec cnfs-nas-static-sts-0 -- ls -arlth /data
Expected output:
total 1G
-rw-r--r-- 1 root root 1.0G Dec 15 12:11 1G.tmpfile
The output indicates that the 1G.tmpfile file is written to the /data directory.
Step 4: Check whether the data is shared with other pods
Check whether the 1 GB temporary file is shared in another Pod cnfs-nas-static-sts-1:
kubectl exec cnfs-nas-static-sts-1 -- ls -arlth /data
Expected output:
total 1G
-rw-r--r-- 1 root root 1.0G Dec 15 12:11 1G.tmpfile
The output indicates that the 1G.tmpfile file exists in the pods named cnfs-nas-static-sts-0 and cnfs-nas-static-sts-1.
When writing shared storage data across different Pods, CNFS does not guarantee data consistency. Avoid writing to the same file multiple times to prevent file corruption.
References
-
If you need to mount different directories of a NAS file system across multiple applications or Pods to achieve storage isolation, see Use CNFS to manage isolated NAS volumes (recommended).
-
If you need to trigger automatic expansion when the usage of a NAS storage volume exceeds a specific threshold, see Use CNFS to auto-scale NAS volumes.