All Products
Search
Document Center

File Storage NAS:Use Flexvolume for NAS storage

Last Updated:Sep 01, 2026

NAS provides shared, persistent storage for workloads where multiple Pods need to share data. This topic describes how to implement shared and persistent storage by using NAS.

Prerequisites

Background information

A NAS file system can be mounted by multiple Pods concurrently. If multiple Pods modify the same data, your application must handle data synchronization.

Use cases for stateful workloads with NAS:

  • Applications that require high disk I/O.

  • Higher read/write performance than OSS.

  • Cross-host file sharing, such as using NAS as a file server.

How to use NAS for stateful workloads:

  1. Manually create a file system and add a mount target.

  2. Manually create a persistent volume (PV) and a persistent volume claim (PVC).

This topic describes how to use the Alibaba Cloud flexvolume plug-in to access NAS storage with a PV and PVC.

Create a PV

  1. Create a file named pv-nas.yaml.

    apiVersion: v1
    kind: PersistentVolume
    metadata:
      name: pv-nas
      labels:
        alicloud-pvname: pv-nas
    spec:
      capacity:
        storage: 5Gi
      accessModes:
        - ReadWriteMany
      flexVolume:
        driver: "alicloud/nas"
        options:
          server: "***-**.cn-hangzhou.nas.aliyuncs.com"   # Replace this value with your actual mount target.
          path: "/k8s1"
          vers: "4.0"

    Parameter

    Description

    alicloud-pvname

    The name of the PV.

    server

    The mount address of the NAS file system. In the NAS console, click File System List in the left-side navigation pane. Find the target file system and click Manage in the Actions column. On the management page, click Mount Targets. In the Mount Target section, the Mount address provides the value for this parameter.

    path

    The directory path within the NAS file system to mount. If the specified directory does not exist, it is automatically created.

    vers

    (Optional) The version of the NFS mount protocol. Valid values: 3 and 4.0. Default value: 3.

    mode

    (Optional) The permissions of the mounted directory. By default, this parameter is not configured.

    Note
    • You cannot configure access permissions for the root directory of a NAS file system.

    • If the NAS file system contains a large amount of data, setting mode can significantly slow the mount process or cause it to fail. We recommend that you do not configure this parameter.

  2. Run the following command to create the PV.

    kubectl create -f pv-nas.yaml

Verification

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

  2. On the Clusters page, click the name of your cluster or click Details in the Actions column.

  3. In the left-side navigation pane, choose Volumes > Persistent Volumes. The list shows the PV named pv-nas with a capacity of 5Gi, an access mode of ReadWriteMany, a reclaim policy of Retain, and a status of Available. This indicates that the PV is created and not yet bound to a persistent volume claim.

Create a PVC

Create a persistent volume claim (PVC) for the NAS file system. Use a selector to bind this PVC to the specific PV that you created.

  1. Create a file named pvc-nas.yaml.

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

    kubectl create -f pvc-nas.yaml

Verification

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

  2. On the Clusters page, click the name of your cluster or click Details in the Actions column.

  3. In the left-side navigation pane, choose Volumes > Persistent Volume Claims. The list shows the PVC named pvc-nas with a status of Bound, a total capacity of 5Gi, an access mode of ReadWriteMany, and an associated PV named pv-nas.

Create an application

  1. Create a file named nas.yaml.

    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: nginx
            ports:
            - containerPort: 80
            volumeMounts:
              - name: pvc-nas
                mountPath: "/data"
          volumes:
            - name: pvc-nas
              persistentVolumeClaim:
                claimName: pvc-nas
  2. Run the following command to create the Deployment.

    kubectl create -f nas.yaml

Verification

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

  2. On the Clusters page, click Manage Applications in the Actions column for the target cluster.

  3. On the details page of the Cluster, choose Workloads > Deployments in the left-side navigation pane to view the Deployment that you created. In the applications list, click the application name nas-static.

Verify shared storage

  1. Run the following command to view the names of the Pods in the Deployment.

    kubectl get pod

    Expected output:

    NAME                             READY   STATUS    RESTARTS   AGE
    nas-static-f96b6b5d7-r****       1/1     Running   0          9m
    nas-static-f96b6b5d7-w****       1/1     Running   0          9m
  2. Run the following command to list the files in the /data directory.

    kubectl exec nas-static-f96b6b5d7-r**** -- ls /data                    
    Note

    The /data directory is empty.

  3. Run the following command to create a file named nas in the /data directory of one of the Pods.

    kubectl exec nas-static-f96b6b5d7-r**** -- touch /data/nas
  4. Check the files in the Pods.

    Run the following command to check the files in the /data directory of the Pod.

    kubectl exec nas-static-f96b6b5d7-r**** -- ls /data

    Expected output:

    nas

    Run the following command to check the files in the /data directory of the other Pod.

    kubectl exec nas-static-f96b6b5d7-w**** -- ls /data

    Expected output:

    nas
    Note

    The file created in the /data directory of one Pod also appears in the /data directory of the other Pod. This indicates that the two Pods share the same NAS file system.

Verify persistent storage

  1. Run the following command to delete the application's Pods.

    kubectl delete pod nas-static-f96b6b5d7-r**** nas-static-f96b6b5d7-wthmb

    Expected output:

    pod "nas-static-f96b6b5d7-r****" deleted
    pod "nas-static-f96b6b5d7-w****" deleted
  2. Run the following command to watch as Kubernetes deletes and recreates the Pods.

    kubectl get pod -w -l app=nginx

    Expected output:

    NAME                             READY   STATUS              RESTARTS       AGE
    nas-static-f96b6b5d7-r****       1/1     Running             0              27m
    nas-static-f96b6b5d7-w****       1/1     Running             0              27m
    nas-static-f96b6b5d7-r****       1/1     Terminating         0              28m
    nas-static-f96b6b5d7-w****       0/1     Pending             0              0s
    nas-static-f96b6b5d7-w****       0/1     Pending             0              0s
    nas-static-f96b6b5d7-w****       0/1     ContainerCreating   0              0s
    nas-static-f96b6b5d7-w****       1/1     Terminating         0              28m
    nas-static-f96b6b5d7-n****       0/1     Pending             0              0s
    nas-static-f96b6b5d7-n****       0/1     Pending             0              0s
    nas-static-f96b6b5d7-n****       0/1     ContainerCreating   0              0s
    nas-static-f96b6b5d7-r****       0/1     Terminating         0              28m
    nas-static-f96b6b5d7-w****       0/1     Terminating         0              28m
    nas-static-f96b6b5d7-r****       0/1     Terminating         0              28m
    nas-static-f96b6b5d7-r****       0/1     Terminating         0              28m
    nas-static-f96b6b5d7-w****       1/1     Running             0              10s
    nas-static-f96b6b5d7-w****       0/1     Terminating         0              28m
    nas-static-f96b6b5d7-w****       0/1     Terminating         0              28m
    nas-static-f96b6b5d7-n****       1/1     Running             0              17s
  3. Run the following command to get the names of the new Pods.

    kubectl get pod

    Expected output:

    NAME                             READY   STATUS    RESTARTS   AGE
    nas-static-f96b6b5d7-n****       1/1     Running   0          21s
    nas-static-f96b6b5d7-w****       1/1     Running   0          21s
  4. Check the files in the Pods.

    Run the following command to check the files in the /data directory of a Pod.

    kubectl exec nas-static-f96b6b5d7-n**** -- ls /data

    Expected output:

    nas

    Run the following command to check the files in the /data directory of the other Pod.

    kubectl exec nas-static-f96b6b5d7-w**** -- ls /data

    Expected output:

    nas
    Note

    The nas file that you created is not deleted. This indicates that the data in the NAS file system persists.