All Products
Search
Document Center

Elastic Container Instance:Mount a NAS volume

Last Updated:Jun 20, 2026

Apsara File Storage NAS (NAS) is a distributed file system provided by Alibaba Cloud that offers shared access, elastic scaling, high reliability, and high performance. After you deploy the Alibaba Cloud CSI plugin, you can use NAS as a volume in your self-managed Kubernetes cluster. You can use static or dynamic provisioning to mount NAS volumes. This topic explains how to use a PersistentVolumeClaim (PVC) to mount a NAS volume to an ECI pod.

Prerequisites

  • A VNode is deployed in your self-managed Kubernetes cluster.

  • Your cluster runs Kubernetes 1.16 or later and has the CSI-Provisioner component deployed.

    Important

    For deployment instructions for the CSI-Provisioner component, see alibaba-cloud-csi-driver. If you encounter issues during deployment, submit an issue on GitHub.

  • If your Kubernetes cluster is deployed in an on-premises data center, ensure a connection exists between the data center and Alibaba Cloud.

Notes

  • NAS provides shared storage, which means you can mount a single NAS volume to multiple pods. If multiple pods modify the same data concurrently, your application must handle data synchronization.

  • Before you unmount the NAS volume, do not delete the NAS mount point. Otherwise, the operating system may become unresponsive.

Static provisioning

  1. Create a NAS file system and a mount point.

    1. Log on to the NAS console.

    2. Create a NAS file system and add a mount point.

      The NAS file system and the mount point must be in the same VPC as the VNode. For more information, see Create a file system and Manage mount points.

  2. Create a PV.

    1. Save the following YAML content as a file named static-nas-pv.yaml. Modify the parameters as described in the table below.

      apiVersion: v1
      kind: PersistentVolume
      metadata:
        name: static-nas-pv
        labels:
          alicloud-pvname: static-nas-pv
      spec:
        capacity:
          storage: 25Gi
        accessModes:
          - ReadWriteMany
        csi:
          driver: nasplugin.csi.alibabacloud.com
          volumeHandle: static-nas-pv
          volumeAttributes:
            server: "2564f4****-ysu87.cn-beijing.nas.aliyuncs.com"
            path: "/test"
        mountOptions:
        - nolock,tcp,noresvport
        - vers=3

      The following table describes the parameters.

      Parameter

      Description

      driver

      The type of the volume provisioner. Set the value to nasplugin.csi.alibabacloud.com to use the Alibaba Cloud CSI plugin.

      volumeHandle

      A unique identifier for the PV. This must be the same as the name defined in metadata.

      server

      The address of the NAS mount point.

      path

      The subdirectory to mount. For an Extreme NAS file system, the path must start with /share, for example, /share/path1.

      vers

      The NFS protocol version for mounting the NAS volume. Version 3 is recommended. Extreme NAS file systems only support version 3.

    2. Run the following command to create the PV:

      kubectl create -f static-nas-pv.yaml
  3. Create a PVC.

    1. Save the following content as static-nas-pvc.yaml.

      apiVersion: v1
      kind: PersistentVolumeClaim
      metadata:
        name: static-nas-pvc
      spec:
        accessModes:
        - ReadWriteMany
        resources:
          requests:
            storage: 25Gi
        selector:
          matchLabels:
            alicloud-pvname: static-nas-pv 
    2. Run the following command to create the PVC:

      kubectl create -f static-nas-pvc.yaml
  4. Mount the NAS volume to an ECI pod.

    1. Save the following content as static-nas-test.yaml.

      apiVersion: apps/v1
      kind: Deployment
      metadata:
        name: static-nas-test
        labels:
          app: nginx
      spec:
        replicas: 2
        selector:
          matchLabels:
            app: nginx
        template:
          metadata:
            labels:
              app: nginx
          spec:
            nodeSelector:    
              k8s.aliyun.com/vnode: "true"
            tolerations:     
            - key: k8s.aliyun.com/vnode
              operator: "Equal"
              value: "true"
              effect: "NoSchedule"
            containers:
            - name: nginx
              image: registry-vpc.cn-beijing.aliyuncs.com/eci_open/nginx:1.14.2
              ports:
              - containerPort: 80
              volumeMounts:
                - name: pvc-nas
                  mountPath: /data
            volumes:
              - name: pvc-nas
                persistentVolumeClaim:
                  claimName: static-nas-pvc
    2. Run the following command to create the Deployment:

      kubectl create -f static-nas-test.yaml
    3. Verify the result.

      kubectl get pods -o wide

      The expected output is similar to the following:

      NAME                              READY   STATUS    RESTARTS   AGE   IP            NODE                                  NOMINATED NODE   READINESS GATES
      
      static-nas-test-5c4b6d4bd-4kggt   1/1     Running   0          95s   172.16.XX.XX   cn-beijing.vnd-2ze8nd8xcl33t4pa****   <none>           <none>
      static-nas-test-5c4b6d4bd-ql6m4   1/1     Running   0          95s   172.16.XX.XX   cn-beijing.vnd-2ze8nd8xcl33t4pa****   <none>           <none>

      Check the directories in the pods. The /data mount directory for the NAS volume is created. A file written to the first pod is also visible in the second, confirming that the two pods share the same NAS storage.

      [root@k8s-master ~]# kubectl exec -it static-nas-test-5c4b6d4bd-4kggt -- bash
      root@static-nas-test-5c4b6d4bd-4kggt:/# ls
      bin  boot  data  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
      root@static-nas-test-5c4b6d4bd-4kggt:/# ls /data
      root@static-nas-test-5c4b6d4bd-4kggt:/# echo "hello nas" > /data/test
      root@static-nas-test-5c4b6d4bd-4kggt:/# ls /data
      test
      root@static-nas-test-5c4b6d4bd-4kggt:/# cat /data/test
      hello nas
      root@static-nas-test-5c4b6d4bd-4kggt:/# exit
      exit
      [root@k8s-master ~]# kubectl exec -it static-nas-test-5c4b6d4bd-ql6m4 -- bash
      root@static-nas-test-5c4b6d4bd-ql6m4:/# ls /data
      test
      root@static-nas-test-5c4b6d4bd-ql6m4:/# cat /data/test
      hello nas

Dynamic provisioning

  1. Create a NAS file system and a mount point.

    1. Log on to the NAS console.

    2. Create a NAS file system and add a mount point.

      The NAS file system and the mount point must be in the same VPC as the VNode. For more information, see Create a file system and Manage mount points.

  2. Create a StorageClass.

    1. Save the following YAML content as a file named nas-sc.yaml. Modify the parameters as described in the table below.

      apiVersion: storage.k8s.io/v1
      kind: StorageClass
      metadata:
        name: alicloud-nas-subpath
      mountOptions:
      - nolock,tcp,noresvport
      - vers=3
      parameters:
        volumeAs: subpath
        server: "0cd8b4a576-g****.cn-hangzhou.nas.aliyuncs.com:/k8s/"
      provisioner: nasplugin.csi.alibabacloud.com
      reclaimPolicy: Retain

      Parameter

      Description

      mountOptions

      The mount options for the NAS volume, such as the NFS protocol version.

      volumeAs

      The type of PV to create. Set this to subpath to use a subdirectory. The CSI-Provisioner automatically creates a subdirectory in the NAS file system.

      server

      The address of the NAS mount point. This is required when you create a PV of the subpath type.

      provisioner

      The type of the volume provisioner. Set the value to nasplugin.csi.alibabacloud.com to use the Alibaba Cloud CSI plugin.

      reclaimPolicy

      The reclaim policy for the PV. The default is Delete. Retain is also supported.

      • Delete: When the PVC is deleted, the PV and the underlying NAS file system are also deleted.

      • Retain: When the PVC is deleted, the PV and the NAS file system are not deleted. You must delete them manually.

      If data security is a high priority, use the Retain policy to prevent accidental data loss.

    2. Run the following command to create the StorageClass:

      kubectl create -f nas-sc.yaml
  3. Create a PVC for the NAS volume.

    1. Save the following content as nas-pvc.yaml.

      kind: PersistentVolumeClaim
      apiVersion: v1
      metadata:
        name: nas-pvc
      spec:
        accessModes:
        - ReadWriteMany
        storageClassName: alicloud-nas-subpath
        resources:
          requests:
            storage: 25Gi
    2. Run the following command to create the PVC:

      kubectl create -f nas-pvc.yaml
  4. Mount the NAS volume to an ECI pod.

    1. Save the following content as nas-test.yaml.

      apiVersion: apps/v1
      kind: Deployment
      metadata:
        name: nas-test
        labels:
          app: nginx
      spec:
        replicas: 2
        selector:
          matchLabels:
            app: nginx
        template:
          metadata:
            labels:
              app: nginx
          spec:
            nodeSelector:    
              k8s.aliyun.com/vnode: "true"
            tolerations:     
            - key: k8s.aliyun.com/vnode
              operator: "Equal"
              value: "true"
              effect: "NoSchedule"
            containers:
            - name: nginx
              image: registry-vpc.cn-beijing.aliyuncs.com/eci_open/nginx:1.14.2
              volumeMounts:
                - name: pvc-nas
                  mountPath: /data
            volumes:
              - name: pvc-nas
                persistentVolumeClaim:
                  claimName: nas-pvc
    2. Run the following command to create the Deployment:

      kubectl create -f nas-test.yaml
    3. Verify the result.

      kubectl get pods -o wide

      The expected output is similar to the following:

      NAME                              READY   STATUS    RESTARTS   AGE     IP             NODE                                  NOMINATED NODE   READINESS GATES
      nas-test-76c54d4b4-f7b88          1/1     Running   0          4m41s   172.16.XX.XX   cn-beijing.vnd-2ze8nd8xcl33t4pa****   <none>           <none>
      nas-test-76c54d4b4-lqz4b          1/1     Running   0          4m41s   172.16.XX.XX   cn-beijing.vnd-2ze8nd8xcl33t4pa****   <none>           <none>

      Check the directories in the pods. The /data mount directory for the NAS volume is created. A file written to the first pod is also visible in the second, confirming that the two pods share the same NAS storage.

      [root@k8s-master ~]# kubectl exec -it nas-test-76c54d4b4-f7b88 -- bash
      root@nas-test-76c54d4b4-f7b88:/# ls
      bin  boot  data  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
      root@nas-test-76c54d4b4-f7b88:/# ls /data
      root@nas-test-76c54d4b4-f7b88:/# echo "hello nas" >/data/test
      root@nas-test-76c54d4b4-f7b88:/# ls /data
      test
      root@nas-test-76c54d4b4-f7b88:/# cat /data/test
      hello nas
      root@nas-test-76c54d4b4-f7b88:/# exit
      exit
      [root@k8s-master ~]# kubectl exec -it nas-test-76c54d4b4-lqz4b -- bash
      root@nas-test-76c54d4b4-lqz4b:/# ls /data
      test
      root@nas-test-76c54d4b4-lqz4b:/# cat /data/test
      hello nas