All Products
Search
Document Center

Container Service for Kubernetes:Mount a statically provisioned NAS volume

Last Updated:Nov 24, 2025

A NAS volume is a distributed file system that provides shared access, scalability, high reliability, and high performance. This topic describes how to use a statically provisioned Alibaba Cloud NAS volume to implement persistent and shared storage.

Prerequisites

Scenarios

  • Applications that have high requirements for disk I/O.

  • You can implement file sharing across hosts. For example, you can use a NAS volume as a file server.

Considerations

  • When you use an Extreme NAS file system, the path of the volume must be a subdirectory of /share. For example, you can set the subdirectory of the NAS file system that is mounted to a pod to /share/path1.

  • A NAS file system can be mounted to multiple pods at the same time. In this case, the pods may modify the same data. Your application must be able to synchronize data.

    Note

    You cannot modify the permissions, owner, or group of the / directory of a NAS file system.

  • If you set the securityContext.fsgroup parameter in the application template, Kubelet runs the chmod or chown operation after the volume is mounted. This prolongs the mount time.

    Note

    If you have set the securityContext.fsgroup parameter and want to reduce the mount time, see The mount time of a NAS volume is prolonged.

Use a statically provisioned NAS volume in the console

Step 1: Create a Persistent Volume (PV)

  1. Log on to the ACK console. In the left navigation pane, click Clusters.

  2. On the Clusters page, find the cluster that you want to manage and click the name of the cluster or click Details in the Actions column. The details page of the cluster appears.

  3. In the left-side navigation pane of the cluster details page, choose Volumes > Persistent Volumes.

  4. On the Persistent Volumes page, click Create in the upper-left corner.

  5. In the Create PV dialog box, set the parameters.

    Parameter

    Description

    PV Type

    In this example, select NAS.

    Name

    The name of the PV. The name must be unique in the cluster. In this example, pv-nas is used.

    Capacity

    The capacity of the PV. Note that NAS file systems do not have a capacity limit. This parameter specifies the capacity of the PV, not the capacity limit of the NAS file system.

    Access Mode

    Select ReadWriteMany or ReadWriteOnce. The default value is ReadWriteMany.

    Mount Target Domain Name

    You can Select Mount Target or specify a Custom mount target as the mount address for the cluster to access the NAS file system.

    Advanced Options (Optional)

    Mount Path

    Subdirectory in the NAS file system to mount.

    • If not set, defaults to root (/for General-purpose NAS, /share for Extreme NAS).

    • If the directory doesn't exist, it will be created.

    Note

    For Extreme NAS, paths must start with /share, such as /share/data.

    Reclaim Policy

    The default value is Retain. This indicates that when a PVC is deleted, the related PV and NAS file system are retained and can only be manually deleted.

    Mount Options

    NAS mount parameter, including NFS protocol version. We recommend using NFS v3 protocol, because Extreme NAS only supports NFS v3. For more information about the NFS protocol, see NFS protocol.

    Label

    Add labels to the PV.

  6. After you set the parameters, click OK.

Step 2: Create a Persistent Volume Claim (PVC)

  1. In the left-side navigation pane of the details page, choose Volumes > Persistent Volume Claims.

  2. On the Persistent Volume Claims page, click Create in the upper-left corner.

  3. In the Create PVC dialog box, set the parameters.

    Parameter

    Description

    PVC Type

    In this example, select NAS.

    Name

    The name of the PVC. The name must be unique in the cluster.

    Allocation Mode

    Select Existing Volumes.

    Note

    If no PV is created, you can set Allocation Mode to Create Volume and set the parameters to create a PV. For more information, see Create a PV.

    Existing Volumes

    Click Select PV, find the target PV, and then click Select in the Actions column.

    Capacity

    The capacity of the PV.

    Note

    The capacity claimed by the PVC cannot exceed the capacity of the PV that is bound to the PVC.

  4. Click OK.

    After the PVC is created, you can view it in the list. The status of the PVC changes to Bound, which indicates that it is bound to the corresponding PV.

Step 3: Create an application

  1. In the navigation pane on the left of the cluster details page, go to Workloads > Deployments.

  2. On the Deployments page, click Create From Image.

  3. Configure the parameters of the application. After doing so, click Create.

    The following table describes the key parameters. Use default settings for other parameters. For more information, see Create a stateless application using a Deployment.

    Section

    Parameter

    Description

    Example

    Basic Information

    Name

    Enter a custom name for the Deployment. The name must meet the format requirements displayed in the console.

    nas-test

    Replicas

    Number of pod replicas.

    2

    Container

    Image Name

    Container image.

    anolis-registry.cn-zhangjiakou.cr.aliyuncs.com/openanolis/nginx:1.14.1-8.6

    Required Resources

    CPU and memory.

    0.25 Core, 512 MiB

    Volume

    Click Add PVC and configure the parameters.

    • Mount Source: Select the PVC that you created.

    • Container Path: Specify the container path to which you want to mount the NAS file system.

    • Mount Source: pvc-nas

    • Container Path: /data

  4. View the application deployment status.

    1. On the Deployments page, click the name of the application.

    2. On the Pods tab, confirm pods are in the Running state.

Use a statically provisioned NAS volume using kubectl

  1. Run the following command to create a statically provisioned PV.

    kubectl create -f pv-nas.yaml

    The following code provides a sample YAML file for creating a statically provisioned PV.

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

    Parameter

    Description

    name

    The name of the PV.

    labels

    The labels of the PV.

    storage

    The available capacity of the NAS file system.

    accessModes

    The access mode.

    driver

    The type of the driver. In this example, the value is nasplugin.csi.alibabacloud.com, which indicates that the Alibaba Cloud NAS CSI plug-in is used.

    volumeHandle

    The unique ID of the PV. If you want to use multiple PVs at the same time, the value of this parameter must be unique for each PV.

    server

    The NAS mount target.

    path

    The subdirectory to mount. For an Extreme NAS file system, the subdirectory must be a subdirectory of /share.

    vers

    The version number of the NFS protocol that is used to mount the NAS volume. We recommend that you use v3. Extreme NAS file systems support only v3.

  2. Run the following command to create a statically provisioned PVC.

    Create a PVC for the NAS file system. Use the selector field to filter PVs and bind the PVC to a specific PV.

    kubectl create -f pvc-nas.yaml

    The following code provides a sample YAML file for creating a statically provisioned PVC.

    kind: PersistentVolumeClaim
    apiVersion: v1
    metadata:
      name: pvc-nas
    spec:
      accessModes:
        - ReadWriteMany
      resources:
        requests:
          storage: 5Gi
      selector:
        matchLabels:
          alicloud-pvname: pv-nas

    Parameter

    Description

    name

    The name of the PVC.

    accessModes

    The access mode.

    storage

    The capacity requested by the application. The value cannot be greater than the total capacity of the PV.

    matchLabels

    The labels of the PV to associate.

  3. Run the following command to create an application named nas-static and mount the PVC.

    kubectl create -f nas.yaml

    The following code provides a sample nas.yaml file for creating the nas-static application.

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: nas-static
      labels:
        app: nginx
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: nginx
      template:
        metadata:
          labels:
            app: nginx
        spec:
          containers:
          - name: nginx
            image: registry.cn-hangzhou.aliyuncs.com/acs-sample/nginx:latest
            ports:
            - containerPort: 80
            volumeMounts:
              - name: pvc-nas
                mountPath: "/data"
          volumes:
            - name: pvc-nas
              persistentVolumeClaim:
                claimName: pvc-nas

    Parameter

    Description

    mountPath

    The path to which the NAS volume is mounted in the container.

    claimName

    The name of the PVC to bind.

  4. Run the following command to view pod information.

    kubectl get pod

    Expected output:

    NAME                          READY   STATUS    RESTARTS   AGE
    nas-static-5b5cdb85f6-n****   1/1     Running   0          32s
    nas-static-c5bb4746c-4****    1/1     Running   0          32s

Verify the persistence of the NAS volume

  1. View the deployed application and NAS files.

    1. Run the following command to view the names of the pods for the deployed application.

      kubectl get pod 

      Expected output:

      NAME                          READY   STATUS    RESTARTS   AGE
      nas-static-5b5cdb85f6-n****   1/1     Running   0          32s
      nas-static-c5bb4746c-4****    1/1     Running   0          32s
    2. Run the following command to view the files in the /data path of one of the application pods. This topic uses the pod named nas-static-5b5cdb85f6-n**** as an example.

      kubectl exec nas-static-5b5cdb85f6-n**** -- ls /data

      The command returns no output, which indicates that no file exists in the /data path.

  2. Run the following command to create a file named nas in the /data path of the nas-static-5b5cdb85f6-n**** pod.

    kubectl exec nas-static-5b5cdb85f6-n**** -- touch /data/nas
  3. Run the following command to view the files in the /data path of the nas-static-5b5cdb85f6-n**** pod.

    kubectl exec nas-static-5b5cdb85f6-n**** -- ls /data

    Expected output:

    nas
  4. Run the following command to delete the pod.

    kubectl delete pod nas-static-5b5cdb85f6-n****
  5. In another window, run the following command to monitor the deletion of the pod and the creation of a new pod by Kubernetes.

    kubectl get pod -w -l app=nginx
  6. Verify that the file created in the NAS volume still exists after the pod is deleted.

    1. Run the following command to view the name of the pod that is recreated by Kubernetes.

      kubectl get pod

      Expected output:

      NAME                                READY   STATUS    RESTARTS   AGE
      nas-static-5b5cdb85f6-n****   1/1     Running   0          32s
      nas-static-c5bb4746c-4****    1/1     Running   0          32s
    2. Run the following command to view the files in the /data path of the nas-static-5b5cdb85f6-n**** pod.

      kubectl exec nas-static-5b5cdb85f6-n**** -- ls /data

      Expected output:

      nas

      The nas file still exists, which indicates that the data in the NAS volume is persistent.

Verify the shared storage of the NAS volume

  1. View the pods where the application is deployed and the NAS files.

    1. Run the following command to view the names of the pods where the application is deployed.

      kubectl get pod 

      Expected output:

      NAME                          READY   STATUS    RESTARTS   AGE
      nas-static-5b5cdb85f6-n****   1/1     Running   0          32s
      nas-static-c5bb4746c-4****    1/1     Running   0          32s
    2. Run the following command to view the files in the /data path of the two pods.

      kubectl exec nas-static-5b5cdb85f6-n**** -- ls /data
      kubectl exec nas-static-c5bb4746c-4**** -- ls /data
  2. Run the following command to create a file named nas in the /data path of one of the pods.

     kubectl exec nas-static-5b5cdb85f6-n**** -- touch /data/nas
  3. Run the following command to view the files in the /data path of the two pods.

    1. Run the following command to view the files in the /data path of the pod named nas-static-5b5cdb85f6-n****.

      kubectl exec nas-static-5b5cdb85f6-n**** -- ls /data

      Expected output:

      nas
    2. Run the following command to view the files in the /data path of the pod named nas-static-c5bb4746c-4****.

      kubectl exec nas-static-c5bb4746c-4**** -- ls /data

      Expected output:

      nas

      If the file created in the /data path of one pod also exists in the /data path of the other pod, it indicates that the two pods share the same NAS volume.