All Products
Search
Document Center

Container Service for Kubernetes:Use CNFS to manage shared NAS volumes (recommended)

Last Updated:Sep 24, 2026

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.

    Note

    For 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 named cnfs-nas-filesystem, which is the NAS file system you have created.

  • Create a persistent volume claim (PVC) named cnfs-nas-static-pvc and 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 data 1G.tmpfile to the mount point.

Show YAML content:

cat << EOF | kubectl apply -f -
apiVersion: v1
kind: PersistentVolume
metadata:
  name: cnfs-nas-static-pv
spec:
  accessModes:
  - ReadWriteOnce
  capacity:
    storage: 50Gi
  csi:
    driver: nasplugin.csi.alibabacloud.com
    fsType: nfs
    volumeAttributes:
      containerNetworkFileSystem: cnfs-nas-filesystem # Reference the CNFS named cnfs-nas-filesystem. 
      mountProtocol: nfs
      path: /
      volumeAs: subpath
      volumeCapacity: "true"
    volumeHandle: cnfs-nas-static-pv
  mountOptions:
  - nolock,tcp,noresvport
  - vers=3
  persistentVolumeReclaimPolicy: Retain
  storageClassName: cnfs-nas-sc
  volumeMode: Filesystem
---
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: cnfs-nas-static-pvc
  namespace: default
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 50Gi
  storageClassName: cnfs-nas-sc
  volumeMode: Filesystem
  volumeName: cnfs-nas-static-pv # Reference the PV named cnfs-nas-static-pv. 
status:
  accessModes:
  - ReadWriteOnce
  capacity:
    storage: 50Gi
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: cnfs-nas-static-sts
  labels:
    app: busybox
spec:
  serviceName: "busybox"
  replicas: 2
  selector:
    matchLabels:
      app: busybox
  template:
    metadata:
      labels:
        app: busybox
    spec:
      containers:
      - name: busybox
        image: busybox
        command: ["/bin/sh"]
        args: ["-c", "sleep 3600;"]
        volumeMounts:
        - mountPath: "/data"
          name: cnfs-nas-static-pvc
      volumes:
      - name: cnfs-nas-static-pvc
        persistentVolumeClaim:
          claimName: cnfs-nas-static-pvc # Reference the PVC named cnfs-nas-static-pvc. 
EOF

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.

Note

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