With dynamic provisioning for File Storage NAS, you can automatically provision storage for workloads on demand, eliminating the need to create PVs in advance. This feature provides data persistence and sharing, allowing multiple Pods to read and write simultaneously, and simplifies storage management for use cases like web applications and log retention.
Prerequisites
The csi-plugin and csi-provisioner components are installed.
CSI components are installed by default. Verify that they remain installed. You can check the installation status on the page. We recommend upgrading the CSI components to the latest version.
To use subpath and sharepath, you need an Apsara File Storage NAS file system that meets the following requirements. Otherwise, create a file system.
NAS has limitations on mount connectivity, the number of file systems, and protocol types.
Protocol: Only NFS is supported.
VPC: The Apsara File Storage NAS file system must be in the same VPC as your cluster. Apsara File Storage NAS supports cross-zone mounting but not cross-VPC mounting.
Mount Target: Add a mount target that is in the same VPC as your cluster and is active. For more information, see Manage mount targets. Note the mount target address.
(Optional) Encryption Type: To encrypt data in a volume, configure the encryption type when you create the Apsara File Storage NAS file system.
Usage notes
Do not delete mount targets: To prevent node I/O errors, do not delete a mount target in the NAS console while its corresponding volume is in use.
Concurrent writes: NAS provides shared storage. When multiple Pods mount the same volume, your application must handle potential data consistency issues from concurrent writes.
For more information about limitations on concurrent writes to NAS, see Multiple processes writing to the same log file and Latency in reading updated file content across ECS instances.
Mount performance: If you configure the
securityContext.fsgroupparameter in your application, kubelet recursively runschmodorchownafter the volume is mounted, significantly increasing Pod startup time.To optimize mount performance, see NAS volume FAQ.
Mount mode
You can specify the mount mode with the volumeAs parameter in a StorageClass. This parameter defines the relationship between a PV and the NAS file system.
Mount mode | Description | Scenario |
In subpath mode, each PV is mapped to a unique subdirectory within a NAS file system. This mode facilitates data isolation. |
| |
In sharepath mode, all PVs map to the same NAS directory defined in the StorageClass. Therefore, all PVCs using this StorageClass access the same shared directory. | Multiple Pods across different namespaces need to mount the same NAS subdirectory. | |
filesystem (Not recommended) | In file system mode, a new, dedicated NAS file system instance is dynamically created for each PV. | This mode is suitable for applications that require strict isolation in terms of performance and security. It enables the dynamic creation and deletion of independent NAS file systems and mount targets for each application, but incurs higher costs. |
Method 1: Mount a volume using subpath
In this method, the CSI provisioner automatically creates a dedicated subpath in the NAS file system for each PersistentVolumeClaim (PVC). This subpath functions as the PersistentVolume (PV).
The version of the CSI plug-in must be 1.31.4 or later. To upgrade the plug-in, see Upgrade the CSI plug-in.
You have created a NAS file system and have its mount target.
1. Create a StorageClass
A StorageClass acts as a template for provisioning dynamic volumes and defines the source and behavior of the storage resources.
kubectl
Create a file named
alicloud-nas-subpath.yamlwith the following content:apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: # The name of the StorageClass, which must be unique within the cluster. name: alicloud-nas-subpath mountOptions: - nolock,tcp,noresvport - vers=3 parameters: # Set to subpath. volumeAs: subpath # The format of the server field is <nas-server-address>:/<path>. server: "0cd8b4a576-g****.cn-hangzhou.nas.aliyuncs.com:/k8s" archiveOnDelete: "true" provisioner: nasplugin.csi.alibabacloud.com reclaimPolicy: Retain allowVolumeExpansion: trueParameter
Description
mountOptionsThe mount options for NAS, including the NFS protocol version. By default, volumes are mounted using NFSv3. You can specify a different version with an option such as
vers=4.0. For information about the NFS protocols supported by different NAS types, see NFS protocols.parameters.volumeAsThe volume provisioning mode. Set to
subpath.parameters.serverThe NAS mount target and the subpath to mount, in the format
<nas-server-address>:/<path>.<nas-server-address>: The mount target of the NAS file system. For more information, see Manage mount targets.:/<path>: The NAS subpath to mount. If this parameter is not set or the specified subpath does not exist, the root directory is mounted by default.General-purpose NAS: The root directory is
/.Extreme NAS: The root directory is
/share. When you mount a subpath, thepathmust start with/share, such as/share/data.
parameters.archiveOnDeleteSpecifies whether to delete the data on the backend storage when a PVC is deleted and its
reclaimPolicyis set toDelete.This option acts as a safeguard to prevent accidental data loss on shared NAS storage.
true(default): The directory and its files are not deleted. Instead, they are archived and renamed in the formatarchived-{pvName}.{timestamp}.false: The corresponding directory and its data are permanently deleted.This operation deletes the NAS subpath and its files, not the NAS file system itself.
To delete a NAS file system, see Delete a file system.
In scenarios where PVs are frequently created and deleted, setting this parameter to
falsemay cause the CSI controller's task queue to become blocked, which prevents new PVs from being created. For more information, see The controller's task queue is full and new PVs cannot be created when you use a dynamic NAS volume.provisionerThe driver. Set this parameter to
nasplugin.csi.alibabacloud.comwhen you use the Alibaba Cloud NAS CSI plug-in.reclaimPolicyThe reclaim policy of the PV.
Delete(default): When the PVC is deleted, the backend storage data is processed based on thearchiveOnDeletesetting.Retain: When the PVC is deleted, the PV and the data in the NAS file system are not deleted and must be deleted manually. This policy is recommended for scenarios that require high data security to prevent accidental data loss.
allowVolumeExpansionSupported only by General-purpose NAS.
Allows dynamic expansion of PVs created by this StorageClass by modifying the PVC capacity.
This StorageClass uses the NAS directory quota feature to manage PV capacity, enabling precise size control. You can expand the volume online by editing the
spec.resources.requests.storagefield of the PVC. For more information, see Set directory quotas for dynamic NAS volumes.NAS directory quotas take effect asynchronously. If you perform high-speed, large-volume data writes immediately after a PV is created or expanded, you may exceed the specified capacity because the quota is not yet fully enforced. For more information, see Usage limits.
Create the StorageClass.
kubectl create -f alicloud-nas-subpath.yaml
Console
-
Log on to the ACK console. In the left navigation pane, click Clusters.
-
On the Clusters page, click the name of your cluster. In the left navigation pane, click .
Click Create, specify a unique name for the StorageClass within the cluster, select NAS as the PV Type, and then follow the on-screen instructions to create the StorageClass.
The key parameters are described in the following table.
Parameter
Description
Select Mount Target
The mount target of the NAS file system.
Volume Mode
The volume provisioning mode. Select Subdirectory. A subpath is automatically created under the specified mount path. Data is stored at
<NAS mount target>:<mount path>/<pv-name>/.Mount Path
The NAS subdirectory to mount. If this parameter is not specified, the root directory is mounted by default.
If the directory does not exist in the NAS file system, it is automatically created and then mounted.
General-purpose NAS: The root directory is
/.Extreme NAS: The root directory is
/share. When you mount a subdirectory, thepathmust start with/share, such as/share/data.
Reclaim Policy
The reclaim policy of the PV.
Delete(default): When the PVC is deleted, the backend storage data is processed based on thearchiveOnDeletesetting.Retain: When the PVC is deleted, the PV and the data in the NAS file system are not deleted and must be deleted manually. This policy is recommended for scenarios that require high data security to prevent accidental data loss.
Mount Options
The mount options for NAS, including the NFS protocol version. By default, volumes are mounted using NFSv3. You can specify a different version with an option such as
vers=4.0. For information about the NFS protocols supported by different NAS types, see NFS protocols.After the StorageClass is created, you can view it in the StorageClasses list.
2. Create a PVC
A PersistentVolumeClaim (PVC) is an application's request for storage that triggers an associated StorageClass to dynamically provision and bind a matching PersistentVolume (PV).
kubectl
Create a file named
nas-pvc.yamlwith the following content:kind: PersistentVolumeClaim apiVersion: v1 metadata: name: nas-csi-pvc spec: accessModes: - ReadWriteMany # Specify the StorageClass to use. storageClassName: alicloud-nas-subpath resources: requests: # Declare the required capacity of the storage volume. storage: 20GiParameter
Description
accessModesThe access mode. Valid values:
ReadWriteMany(default): The volume can be mounted as read-write by many nodes.ReadWriteOnce: The volume can be mounted as read-write by a single node.ReadOnlyMany: The volume can be mounted as read-only by many nodes.
storageClassNameThe name of the StorageClass to use.
storageThe required capacity of the storage volume. By default, this declaration acts as a resource request and does not limit the actual storage space available to the pod.
The capacity limit of a NAS file system is determined by its specifications. For more information, see General-purpose NAS and Extreme NAS.
However, when
allowVolumeExpansionin the StorageClass is set totrue, this value becomes a strictly enforced hard limit. The CSI plug-in sets the NAS directory quota based on this configuration to limit the available capacity of the PV.Create the PVC.
kubectl create -f nas-pvc.yamlCheck the PV.
kubectl get pvThe expected output is similar to the following, which shows that the StorageClass automatically provisioned a PersistentVolume (PV) and bound it to the PVC.
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS VOLUMEATTRIBUTESCLASS REASON AGE nas-a7540d97-0f53-4e05-b7d9-557309****** 20Gi RWX Retain Bound default/nas-csi-pvc alicloud-nas-subpath <unset> 5m
Console
In the left navigation pane of the cluster management page, choose .
On the Persistent Volume Claims page, click Create, configure the PVC parameters, and then click Create.
Parameter
Description
PVC Type
Select NAS.
Name
The name of the PVC. The name must be unique within the namespace.
Allocation Mode
Select Use StorageClass.
Existing Storage Class
Click Select Storage Class and choose the StorageClass that you created.
Total Capacity
The required capacity of the storage volume. By default, this declaration acts as a resource request and does not limit the actual storage space available to the pod.
The capacity limit of a NAS file system is determined by its specifications. For more information, see General-purpose NAS and Extreme NAS.
However, when
allowVolumeExpansionin the StorageClass is set totrue, this value becomes a strictly enforced hard limit. The CSI plug-in sets the NAS directory quota based on this configuration to limit the available capacity of the PV.Access Mode
The access mode. Valid values:
ReadWriteMany(default): The volume can be mounted as read-write by many nodes.ReadWriteOnce: The volume can be mounted as read-write by a single node.ReadOnlyMany: The volume can be mounted as read-only by many nodes.
3. Create an application and mount NAS
After the PVC is created, you can mount the volume to an application. This section shows how to create two Deployments that reference the same PVC, allowing multiple pods to share the same NAS subpath.
kubectl
Create two Deployments that reference the same PVC to allow them to share the same subpath of the NAS file system.
To mount different subpaths from the same NAS file system to different pods, you must create a unique StorageClass and a corresponding PVC for each subpath.
Create two files named
nginx-1.yamlandnginx-2.yamlwith the following content.The configurations for both applications are nearly identical. They both reference the same PVC.
Create the two Deployments.
kubectl create -f nginx-1.yaml -f nginx-2.yamlCheck the status of the pods.
kubectl get pod -l app=nginxExpected output:
NAME READY STATUS RESTARTS AGE nas-test-1-b75d5b6bc-***** 1/1 Running 0 51s nas-test-2-b75d5b6bc-***** 1/1 Running 0 44sInspect each pod to verify that it uses the correct PersistentVolumeClaim (PVC).
Replace
<podName>with the actual name of each pod.kubectl describe pod <podName> | grep "ClaimName:"In the expected output, both pods use the same PVC, which confirms that they share the same subpath of the NAS file system.
Console
Repeat the following steps to create two Deployments that use the same PVC, which allows them to share the same subpath of the NAS file system.
-
On the ACK Clusters page, click the name of your cluster. In the left navigation pane, click .
Click Create from Image and follow the on-screen instructions to configure and create the application.
The key parameters are described below. You can keep the default values for other parameters. For more information, see Create a stateless application (Deployment).
Section
Parameter
Description
Basic Information
Replicas:
The number of replicas for the Deployment.
Container
Image
The address of the image used to deploy the application.
Required Resources
The vCPU and memory resources required by the container.
Volumes
Click Add PVC and then configure the parameters.
Mount Source: Select the PVC that you created.
Container Path: Enter the path within the container where the NAS file system will be mounted.
After the deployment is complete, you can click the application name on the Deployments page and check the Pods tab to confirm that the pods are running properly (their status is Running).
To verify that the storage is shared and persistent, see Verify shared and persistent storage.
Method 2: Mount using sharepath mode
In this mode, when PVs are created for PVCs that use this StorageClass, the provisioner does not create new directories. Instead, all PVs use the path defined in the StorageClass, mapping each PV to the same NAS directory.
1. Create a StorageClass
A StorageClass acts as a template for provisioning dynamic volumes and defines the source and behavior of the storage resources.
kubectl
Create a file named alicloud-nas-sharepath.yaml with the following content.
apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: alicloud-nas-sharepath mountOptions: - nolock,tcp,noresvport - vers=3 parameters: volumeAs: sharepath # The format of the server field is <nas-server-address>:/<path> server: "0cd8b4a576-g****.cn-hangzhou.nas.aliyuncs.com:/k8s" provisioner: nasplugin.csi.alibabacloud.com reclaimPolicy: RetainParameter
Description
mountOptionsThe mount options for NAS, including the NFS protocol version. By default, volumes are mounted using NFSv3. You can specify a different version with an option such as
vers=4.0. For information about the NFS protocols supported by different NAS types, see NFS protocols.parameters.volumeAsThe volume provisioning mode. Set to
sharepath.parameters.serverThe NAS mount target and the subpath to mount, in the format
<nas-server-address>:/<path>.<nas-server-address>: The mount target of the NAS file system. For more information, see Manage mount targets.:/<path>: The NAS subpath to mount. If this parameter is not set or the specified subpath does not exist, the root directory is mounted by default.General-purpose NAS: The root directory is
/.Extreme NAS: The root directory is
/share. When you mount a subpath, thepathmust start with/share, such as/share/data.
provisionerThe driver. Set this parameter to
nasplugin.csi.alibabacloud.comwhen you use the Alibaba Cloud NAS CSI plug-in.reclaimPolicyThe reclaim policy for the PV. For
sharepathmode, this must be Retain.Create the StorageClass.
kubectl create -f alicloud-nas-sharepath.yaml
Console
-
On the Clusters page, click the name of your cluster. In the left navigation pane, click .
Click Create, specify a unique name for the StorageClass, and select NAS as the PV Type.
Parameter
Description
Select Mount Target
The mount target of the NAS file system.
Volume Mode
The volume provisioning mode. In this example, select Shared Directory, which enables sharepath mode.
Mount Path
The NAS subdirectory to mount. If this parameter is not specified, the root directory is mounted by default.
If the directory does not exist in the NAS file system, it is automatically created and then mounted.
General-purpose NAS: The root directory is
/.Extreme NAS: The root directory is
/share. When you mount a subdirectory, thepathmust start with/share, such as/share/data.
Reclaim policy
For
sharepathmode, this must be Retain.Mount options
The mount options for NAS, including the NFS protocol version. By default, volumes are mounted using NFSv3. You can specify a different version with an option such as
vers=4.0. For information about the NFS protocols supported by different NAS types, see NFS protocols.
2. Create a PVC
A PersistentVolumeClaim (PVC) is an application's request for storage that triggers an associated StorageClass to dynamically provision and bind a matching PersistentVolume (PV).
To enable data sharing across namespaces, you will create a PVC with the same name in two different namespaces. Although the PVCs share a name, they are distinct resources because they are in different namespaces. The StorageClass provisions a separate PV for each PVC, and both PVs point to the same shared directory on the NAS file system.
kubectl
Create two namespaces,
ns1andns2.kubectl create ns ns1 kubectl create ns ns2Create a file named pvc.yaml with the following content to create a PVC with the same name in both the
ns1andns2namespaces.kind: PersistentVolumeClaim apiVersion: v1 metadata: name: nas-csi-pvc namespace: ns1 spec: accessModes: - ReadWriteMany storageClassName: alicloud-nas-sharepath resources: requests: storage: 20Gi --- kind: PersistentVolumeClaim apiVersion: v1 metadata: name: nas-csi-pvc namespace: ns2 spec: accessModes: - ReadWriteMany storageClassName: alicloud-nas-sharepath resources: requests: storage: 20GiParameter
Description
accessModesThe access mode. Valid values:
ReadWriteMany(default): The volume can be mounted as read-write by many nodes.ReadWriteOnce: The volume can be mounted as read-write by a single node.ReadOnlyMany: The volume can be mounted as read-only by many nodes.
storageClassNameThe name of the StorageClass to use.
storageThe required capacity of the storage volume. By default, this declaration acts as a resource request and does not limit the actual storage space available to the pod.
The capacity limit of a NAS file system is determined by its specifications. For more information, see General-purpose NAS and Extreme NAS.
However, when
allowVolumeExpansionin the StorageClass is set totrue, this value becomes a strictly enforced hard limit. The CSI plug-in sets the NAS directory quota based on this configuration to limit the available capacity of the PV.Create the PVCs.
kubectl create -f pvc.yamlCheck the PV status to confirm that PVs have been automatically created and bound to the PVCs.
kubectl get pvThe expected output is similar to the following. The status of both PVs is
Bound, and theCLAIMcolumn shows that each PV is bound to a PVC in a different namespace (ns1/nas-csi-pvcandns2/nas-csi-pvc).NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS VOLUMEATTRIBUTESCLASS REASON AGE nas-0b448885-6226-4d22-8a5b-d0768c****** 20Gi RWX Retain Bound ns1/nas-csi-pvc alicloud-nas-sharepath <unset> 74s nas-bcd21c93-8219-4a11-986b-fd934a****** 20Gi RWX Retain Bound ns2/nas-csi-pvc alicloud-nas-sharepath <unset> 74s
Console
Create namespaces.
-
On the Clusters page, click the name of your cluster. In the left navigation pane, click Namespaces and Quotas.
Click Create and follow the on-screen instructions to create the
ns1andns2namespaces.
-
In the left navigation pane of the cluster management page, choose .
In the
ns1namespace, create a storage claim.On the Persistent Volume Claims page, select
ns1from the Namespace dropdown list and follow the on-screen instructions to create the PVC.Parameter
Description
PVC Type
Select NAS.
Name
The name of the PVC. The name must be unique within the namespace.
Allocation Mode
Select Use StorageClass.
Existing Storage Class
Click Select Storage Class and choose the StorageClass that you created.
Capacity
The required capacity of the storage volume. By default, this declaration acts as a resource request and does not limit the actual storage space available to the pod.
The capacity limit of a NAS file system is determined by its specifications. For more information, see General-purpose NAS and Extreme NAS.
However, when
allowVolumeExpansionin the StorageClass is set totrue, this value becomes a strictly enforced hard limit. The CSI plug-in sets the NAS directory quota based on this configuration to limit the available capacity of the PV.Access Mode
The access mode. Valid values:
ReadWriteMany(default): The volume can be mounted as read-write by many nodes.ReadWriteOnce: The volume can be mounted as read-write by a single node.ReadOnlyMany: The volume can be mounted as read-only by many nodes.
Follow the previous step to create another PVC in the
ns2namespace.After creation, return to the Persistent Volume Claims page. In both the
ns1andns2namespaces, confirm that both PVCs are bound to their automatically created PVs.
3. Create an application and mount the NAS
After the PVCs are created, you can mount their bound PVs to your applications. In this section, you will create an application in each of the two namespaces and mount the corresponding PVC. This configuration allows both applications to share the NAS subdirectory defined in the StorageClass.
kubectl
Create two files named
nginx-ns1.yamlandnginx-ns2.yamlwith the following content.The configurations for both applications are nearly identical. They each bind to the PVC in their respective namespace.
Create the two Deployments.
kubectl create -f nginx-ns1.yaml -f nginx-ns2.yamlCheck the Pod status.
kubectl get pod -A -l app=nginxExpected output:
NAMESPACE NAME READY STATUS RESTARTS AGE ns1 nas-test-b75d5b6bc-***** 1/1 Running 0 2m19s ns2 nas-test-b75d5b6bc-***** 1/1 Running 0 2m11sCheck the detailed configuration of a Pod to confirm the PVC mount.
Replace
<namespace-name>and<pod-name>with the actual namespace and Pod name.kubectl describe pod -n <namespace-name> <pod-name> | grep "ClaimName:"In the expected output, the two Pods mount
ns1/nas-csi-pvcandns2/nas-csi-pvcrespectively.
Console
-
On the ACK Clusters page, click the name of your cluster. In the left navigation pane, click .
In the
ns1namespace, create a Deployment and mount the corresponding PVC.Select Namespace from the Namespace dropdown list and click Create from Image.
Follow the on-screen instructions to create the application.
The key parameters are described below. Leave other parameters at their default values. For more information, see Create a stateless Deployment.
Section
Parameter
Description
Basic Information
Replicas:
The replica count of the Deployment.
Container
Image
The address of the image used to deploy the application.
Required Resources
The required vCPU and memory resources.
Volumes
Click Add PVC and configure the parameters.
Mount Source: Select the PVC that you created.
Container Path: Enter the path within the container where the NAS file system will be mounted, such as /data.
Follow the previous step to create another Deployment in the
ns2namespace and mount the corresponding PVC.Return to the Deployments page. In the
ns1andns2namespaces, check the status of each Deployment to confirm that the Pods are running and have mounted the correct PVCs.
To verify the results, see Verify shared and persistent storage.
Method 3: Mount a volume in filesystem mode
The filesystem mode allows you to dynamically create and manage a dedicated NAS file system and mount target for an application. Unlike the sharepath mode, each PV created in filesystem mode corresponds to a separate NAS file system instance.
Each PV of the filesystem type corresponds to a dedicated NAS file system and one mount target.By default, when you delete a PV of the
filesystemtype, the corresponding NAS file system and mount target are retained. To automatically delete the NAS file system and mount target when the PV is deleted, add the following parameters to the StorageClass:reclaimPolicy: Deleteparameters.deleteVolume: "true"
When using an ACK dedicated cluster, grant the necessary permissions to the csi-provisioner.
1. Create a StorageClass
2. Create a PVC
3. Create application and mount NAS
References
If you encounter issues when mounting or using NAS volumes, see the following documents:
CNFS lets you independently manage NAS file systems to improve performance and provide QoS control. For more information, see Managing NAS file systems with CNFS.