All Products
Search
Document Center

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

Last Updated:Mar 26, 2026

Container Network File System (CNFS) lets you mount the same directory of a NAS file system to multiple pods simultaneously. This eliminates data-sharing issues across pods without requiring application-level coordination.

This topic walks you through mounting a NAS file system as a shared volume using a StatefulSet, then verifying that data written by one pod is immediately visible to others.

Before you begin

Review the following constraints before proceeding:

  • The minimum required component versions are: csi-plugin and csi-provisioner at v1.24.11-5221f79-aliyun or later, and storage-operator at v1.24.105-825188d-aliyun or later. If your versions are older, update the components before proceeding.

  • CNFS does not guarantee data consistency when multiple pods write to the same file concurrently.

Prerequisites

Before you begin, ensure that you have:

For background on CNFS and how to manage NAS file systems with it, see CNFS overview and Use CNFS to manage NAS file systems (recommended).

Step 1: Create the workload

Create three resources that wire together your NAS file system and a two-replica StatefulSet:

  • A PersistentVolume (PV) named cnfs-nas-static-pv that references a CNFS object named cnfs-nas-filesystem, which represents your existing NAS file system.

  • A PersistentVolumeClaim (PVC) named cnfs-nas-static-pvc bound to the PV.

  • A StatefulSet named cnfs-nas-static-sts with two replicas, each mounting the PVC at /data.

Run the following command to create all three resources at once:

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 object that represents your NAS file system.
      mountProtocol: nfs
      path: /
      volumeAs: subpath
      volumeCapacity: "true"
    volumeHandle: cnfs-nas-static-pv
  mountOptions:
  - nolock,tcp,noresvport  # nolock: disables NFS file locking; noresvport: improves connection resilience on failover
  - vers=3                 # NFS protocol version; vers=3 is recommended for general workloads
  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 # Bind to the PV created above.
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
EOF

Step 2: Verify the mount

Run the following command to check the NFS mount on the first pod:

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 output shows the NAS mount target at /data. Do not proceed to the next step until you see a mount target in the output.

Step 3: Write data from one pod

Run the following command to write a 1 GiB temporary file from pod cnfs-nas-static-sts-0:

kubectl exec cnfs-nas-static-sts-0 -ti -- sh -c 'dd if=/dev/zero of=/data/1G.tmpfile bs=1G count=1;'

Verify the file was created:

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

Step 4: Verify data sharing across pods

Run the following command to confirm that pod cnfs-nas-static-sts-1 can see the same file:

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

Both pods see 1G.tmpfile, confirming that the shared NAS volume is working correctly.

Important

CNFS does not guarantee data consistency when multiple pods write to the same file concurrently. To prevent file corruption, avoid writing to the same file from multiple pods at the same time.

What's next