File Storage NAS (NAS) is a distributed file system that supports shared access and elastic scaling and provides high reliability and high performance. NAS is suitable for scenarios such as big data analysis, data sharing, web applications, and log storage. The Container Storage Interface (CSI) plug-in allows you to use an existing NAS file system to create persistent volumes (PVs) and persistent volume claims (PVCs) and mount the PVs and PVCs to workloads for persistent storage and shared storage of data.
Prerequisites
The CSI plug-in is installed in the cluster. For more information about how to update csi-plugin and csi-provisioner, see Update csi-plugin and csi-provisioner.
NoteIf FlexVolume is used in your cluster, upgrade FlexVolume to CSI because FlexVolume is deprecated. For more information, see Upgrade from FlexVolume to CSI. Choose and click the Storage tab to check the storage component type.
A kubectl client is connected to the cluster. For more information, see Obtain the kubeconfig file of a cluster and use kubectl to connect to the cluster.
Make sure that the existing NAS file system meets the following requirements. Otherwise, create a new NAS file system that meets the requirements or mount a dynamically provisioned NAS volume. For more information, see Create a file system.
The protocol type is Network File System (NFS). Extreme NAS file systems support only NFSv3.
The mount target and the cluster node to which you want to mount the NAS file system belong to the same virtual private cloud (VPC) and the Status of the mount target is Available. For more information about how to create a mount target, see Manage mount targets.
NoteIf you want to encrypt data in a NAS volume, you can configure the encryption settings when you create the NAS file system.
Limits
You cannot mount NAS file systems that use the Server Message Block (SMB) protocol.
General-purpose and Extreme NAS file systems have different limits on mounting scenarios, the number of file systems, and file sharing protocols. For more information about the supported states, see Limits.
Statically provisioned NAS volumes cannot be expanded.
Usage notes
NAS is a shared storage service. A NAS volume can be mounted to multiple pods. If multiple pods write data at the same time, applications must independently ensure data consistency. For more information about the limits on concurrent writes to NAS, see How do I prevent exceptions that may occur when multiple processes or clients concurrently write data to a log file? and How do I resolve the latency in writing data to an NFS file system?
Do not delete the mount target of a NAS file system. Otherwise, an operating system hang issue may occur.
To mount an Extreme NAS file system, set the
path
parameter of the NAS volume to a subdirectory of/share
. For example, you can specify the/share/path1
subdirectory when you mount an Extreme NAS file system to a pod.If the securityContext.fsgroup parameter is configured in the application template, kubelet performs the
chmod
orchown
operation after the volume is mounted, which increases the time consumption. For more information about how to accelerate the mounting process when the securityContext.fsgroup parameter is configured, see Why does it require a long time to mount a NAS volume?
Step 1: Mount a statically provisioned NAS volume
Use kubectl
Create a statically provisioned PV.
Create a file named pv-nas.yaml and copy the following content to the file:
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 # Specify the name of the PV. volumeAttributes: server: "0c47****-mpk25.cn-shenzhen.nas.aliyuncs.com" # The mount target of the NAS file system, which is the same as the VPC of the cluster. path: "/csi" # Specify the subdirectory of the NAS file system. mountOptions: - nolock,tcp,noresvport - vers=3
Parameter
Description
name
The name of the PV.
labels
The labels that you want to add to the PV
storage
The capacity of the NAS volume.
NoteIn actual scenarios, the capacity of the NAS volume is not limited by the storage parameter. For more information about the available capacity of the NAS volume, see Limits.
accessModes
The access mode of the PV. The default value is
ReadWriteMany
. You can also set the value toReadWriteOnce
orReadOnlyMany
.driver
The type of the storage driver that is used to provision the volume. In this example, the parameter is set to
nasplugin.csi.alibabacloud.com
. This indicates that the CSI plug-in provided by Alibaba Cloud is used.volumeHandle
The unique identifier of the PV. Enter the name of the PV. If multiple PVs are used, the identifier of each PV must be unique.
server
The mount target of the NAS file system, which must be the same as the VPC of the cluster.
NoteReplace the value with the domain name of a mount target. For more information about how to view the domain name of a mount target, see Manage mount targets.
path
The subdirectory of the NAS file system that you want to mount. The parent directory of the General-purpose NAS file system is /.
ImportantIf you want to mount an Extreme NAS file system, set this parameter to a subdirectory of the
/share
directory. Example:/share/csi
.mountOptions
Configure the
options
parameter and specify the NFS version in themountOptions
field. The version of the NFS protocol. We recommend that you use NFSv3. Extreme NAS file systems support only NFSv3. For more information about the NFS protocol, see NFS.Create a statically provisioned PV.
kubectl create -f pv-nas.yaml
When you create a PVC of the NAS type, set the selector parameter to specify how to select a PV and bind the PV to the PVC.
Create a file named pvc-nas.yaml and copy the following content to the file:
kind: PersistentVolumeClaim apiVersion: v1 metadata: name: pvc-nas spec: accessModes: - ReadWriteMany resources: requests: storage: 5Gi selector: matchLabels: alicloud-pvname: pv-nas
Parameter
Description
Example
name
The name of the PVC.
pvc-nas
accessModes
The access mode of the PVC. The default value is
ReadWriteMany
. You can also set the value toReadWriteOnce
orReadOnlyMany
.ReadWriteMany
storage
The claimed capacity of the NAS volume that can be used by the application. The claimed capacity cannot exceed the total capacity of the NAS volume.
NoteIn actual scenarios, the capacity of the NAS volume is not limited by the storage parameter. For more information about the available capacity of the NAS volume, see Limits.
5Gi
matchLabels
The labels used to select a PV and bind the PV to the PVC.
pv-nas
Create a statically provisioned PVC.
kubectl create -f pvc-nas.yaml
Deploy an application named nas-static and associate the PVC with the application.
The following YAML template provides an example of the nas.yaml file that is used to create 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: anolis-registry.cn-zhangjiakou.cr.aliyuncs.com/openanolis/nginx:1.14.1-8.6 ports: - containerPort: 80 volumeMounts: - name: pvc-nas mountPath: "/data" volumes: - name: pvc-nas persistentVolumeClaim: claimName: pvc-nas
Parameter
Description
mountPath
The path of the container to which the NAS volume is mounted.
claimName
The name of the PVC mounted to the application.
Deploy an application named nas-static and associate the PVC with the application.
kubectl create -f nas.yaml
View the 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
Use the ACK console
Step 1: Create a PV
Log on to the ACK console. In the left-side navigation pane, click Clusters.
On the Clusters page, find the cluster that you want to manage and click its name. In the left-side pane, choose .
On the Persistent Volumes page, click Create.
In the Create PV dialog box, configure the parameters and click Create. The following table describes the parameters.
Parameter
Description
Example
PV Type
Select NAS.
NAS
Volume Name
The name of the volume. The name must be unique in the cluster.
pv-nas
Capacity
The capacity of the PV.
NoteA NAS file system provides unlimited capacity. This parameter does not limit the storage usage of the NAS file system but defines the capacity of the PV.
20Gi
Access Mode
You can select ReadWriteMany or ReadWriteOnce. Default value: ReadWriteMany.
ReadWriteMany
Enable CNFS
Specify whether to enable Container Network File System (CNFS). After you enable CNFS, you must perform the following operations:
Select the corresponding CNFS or create a new CNFS. For more information about CNFS, see Use CNFS to manage NAS file systems (recommended).
You can specify whether to enable CNFS acceleration. For more information about CNFS acceleration, see Enable the distributed caching feature of the CNFS client.
Enable
Mount Target Domain Name
You must configure this parameter when CNFS is disabled.
You can select Select Mount Target or Custom to configure the NAS file system that you want to mount. For more information about how to view the domain name of a mount target, see Manage mount targets.
0c47****-mpk25.cn-shenzhen.nas.aliyuncs.co
Advanced Options (Optional)
Mount Path: the mount path of the NAS file system. The mount path must start with a forward slash (
/
), which indicates the root directory. After you configure this parameter, the PV is mounted to the specified subdirectory.If the specified subdirectory does not exist, the system automatically creates the subdirectory in the NAS file system and mounts the subdirectory to the cluster.
If you do not configure this parameter, the root directory of the NAS file system is mounted.
If you want to mount an Extreme NAS file system, set this parameter to a subdirectory of the
/share
directory. Example:/share/data
.
/data
Reclaim Policy: This parameter is set to Delete by default. You can also set this parameter to Retain.
Delete: If the reclaim policy is deleted, you must configure the
archiveOnDelete
parameter.If you set the
archiveOnDelete
parameter totrue
, the related PV and NAS file system are renamed after you delete a PVC. The related PV and NAS file system are not deleted together with the PVC.If you set the
archiveOnDelete
parameter tofalse
, the related PV and NAS file system are also deleted when you delete a PVC.
Retain: When a PVC is deleted, the related PV and NAS file system are retained and can only be manually deleted.
If you have high requirements for data security, we recommend that you use the Retain policy to prevent data loss caused by user errors.
Retain
Mount Options: the optional parameters for mounting a NAS file system, including the version of the NFS protocol. We recommend that you use NFS v3. Extreme NAS file systems support only NFS v3. For more information about the NFS protocol, see NFS.
v3
Label
Add labels to the PV.
pv-nas
After you create the PV, you can view the PV on the Persistent Volumes page.
Step 2: Create a PVC
In the left-side navigation pane of the details page, choose .
On the Persistent Volume Claims page, click Create.
In the Create PVC dialog box, configure the parameters. After you configure the parameters, click Create.
Parameter
Description
Example
PVC Type
Select NAS.
NAS
Name
The name of the PVC. The name must be unique in the cluster.
pvc-nas
Allocation Mode
In this example, Existing Volumes is selected.
NoteIf no PV is created, you can set the Allocation Mode parameter to Create Volume and configure the required parameters to create a PV.
Select Existing Volumes.
Existing Storage Class
Click Select PV. Find the PV that you want to use and click Select in the Actions column.
Existing Volumes
Capacity
The capacity of the PV.
NoteThe capacity claimed by the PVC cannot exceed the capacity of the PV that is bound to the PVC.
20
Access Mode
The default value is ReadWriteMany. You can also set the value to ReadWriteOnce or ReadOnlyMany.
ReadWriteMany
Step 3: Create an application
In the left-side navigation pane of the details page, choose
.On the Deployments tab, click Create from Image.
Configure the parameters of the application. Then, click Create.
The following table describes the key parameters. Retain the default values for other parameters. For more information, see Create a stateless application by 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.
test-nas
Replicas
The number of pod replicas provisioned by the Deployment.
2
Container
Image Name
The address of the image used to deploy the application.
anolis-registry.cn-zhangjiakou.cr.aliyuncs.com/openanolis/nginx:1.14.1-8.6
Required Resources
Specify the number of vCores and the amount of memory required by the application.
0.25 vCores and 0.5 GiB of memory
Volume
Click Add PVC and configure the parameters.
Mount Source: Select the PVC 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
Run the following command to query the deployment progress of the application:
On the Deployments page, click the name of the application that you want to manage.
On the Pods tab, check whether the pod is in the Running state.
Step 2: Verify that the NAS volume can persist and share data
The Deployment you created in the preceding steps contains two pods. The two pods are mounted to the same NAS file system. You can use one of the following methods to verify that the NAS volume can persist and share data.
Recreate the pod. Access the NAS volume from a recreated pod to check whether the original data still exists in the NAS file system. If the data still exists, data persistence is enabled.
Create a file in one pod and access the file from the other pod. If you can access the file, data sharing is enabled.
Verify that the NAS file system can be used to persist data
Query the pod on which the application resides.
kubectl get pod
Expected output:
NAME READY STATUS RESTARTS AGE nas-static-5b5cdb85f6-a**** 1/1 Running 0 32s nas-static-c5bb4746c-b**** 1/1 Running 0 32s
Create a file in a pod.
Check whether a file exists in the
/data
path that is mounted to the application.In this example, the
nas-static-5b5cdb85f6-a****
pod is used.kubectl exec nas-static-5b5cdb85f6-a**** -- ls /data
No output is returned. This indicates that no file exists in the
/data
path.Create a file named nas in the
/data
path of the pod.kubectl exec nas-static-5b5cdb85f6-a**** -- touch /data/nas
Access the file you created from the other pod.
In this example, the
nas-static-5b5cdb85f6-b****
pod is used.kubectl exec nas-static-5b5cdb85f6-b**** -- ls /data
Expected output:
nas
Recreate a pod.
Delete the pod.
kubectl delete pod nas-static-5b5cdb85f6-a****
Open another command-line interface (CLI) and view how the pod is deleted and recreated.
kubectl get pod -w -l app=nginx
Verify that the file still exists after the pod is deleted.
Query the name of the recreated pod.
kubectl get pod
Expected output:
NAME READY STATUS RESTARTS AGE nas-static-5b5cdb85f6-c**** 1/1 Running 0 32s nas-static-c5bb4746c-a**** 1/1 Running 0 32s
Query the files in the
/data
path of the recreated pod.In this example, the
nas-static-5b5cdb85f6-c****
pod is used.kubectl exec nas-static-5b5cdb85f6-c**** -- ls /data
Expected output:
nas
The nas file still exists in the /data path. This indicates that data is persisted to the NAS file system.
Verify that data in the NAS file system can be shared across pods
Query the pod on which the application resides.
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
Query 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
No output is returned. This indicates that no file exists in the
/data
path.Create a file named nas in the
/data
path of a pod:In this example, the
nas-static-5b5cdb85f6-n****
pod is used.kubectl exec nas-static-5b5cdb85f6-n**** -- touch /data/nas
Query the files in the
/data
path of the two pods.Query the files in the
/data
path of thenas-static-5b5cdb85f6-n****
pod.kubectl exec nas-static-5b5cdb85f6-n**** -- ls /data
Expected output:
nas
Query the files in the
/data
path of thenas-static-c5bb4746c-4****
pod.kubectl exec nas-static-c5bb4746c-4**** -- ls /data
Expected output:
nas
When you create a file in the
/data
path of one pod, you can also find the file in the/data
path of the other pod. This indicates that data in the NAS file system is shared by the two pods.
References
For more information about how to mount a NAS file system that has TLS enabled, see How do I use CSI to mount a NAS file system that has TLS enabled?
If you cannot access NAS volumes due to permission issues, see Why does the system prompt chown: Operation not permitted when I mount a NAS volume?
For more information about how to ensure data security between different users and user groups, see FAQ.
For more information about read and write access issues when you use NAS, see FAQ about read and write access to files.
If you want to dynamically resize volumes, use dynamically provisioned NAS volumes. For more information, see Mount a dynamically provisioned NAS volume.
You can specify quotas for the directories of General-purpose NAS volumes to manage the storage space of NAS volumes. For more information, see Expand a NAS volume.
You can directly use NAS volumes or use CNFS to manage NAS volumes to improve the performance and quality of service (QoS) control of NAS.