File Storage NAS (NAS) is a distributed file system that supports shared access, elastic scaling, high reliability, and high performance. It is suitable for scenarios such as big data analysis and data sharing. You can mount a statically provisioned NAS volume in the ACK console or by using kubectl. This topic describes how to mount a statically provisioned NAS volume, and how to test whether the NAS volume can persist and share data as expected.
Prerequisites
An ACK cluster is created. For more information, see Create an ACK managed cluster.
A NAS file system is created. For more information, see Create a file system.
If you want to encrypt data in a NAS volume, configure the encryption settings when you create the NAS file system.
A mount target is created for the NAS file system. For more information, see Manage mount targets.
The mount target and the cluster node to which you want to mount the NAS file system must belong to the same virtual private cloud (VPC).
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.
Scenarios
Your application requires high disk I/O.
You need a storage service that offers higher read and write throughput than Object Storage Service (OSS).
You want to share files across hosts. For example, you want to use a NAS file system as a file server.
Limits
NAS is a shared storage service. A persistent volume claim (PVC) that is used to mount a NAS file system can be shared among pods.
You cannot use the Container Storage Interface (CSI) plug-in to mount Server Message Block (SMB) file systems.
We recommend that you use the NFSv3 file sharing protocol.
You can mount a NAS volume only to ECS instances in the same virtual private cloud (VPC) as the NAS file system.
General-purpose and Extreme NAS file systems have different limits such as the limits on mounting connectivity, the number of file systems, and file sharing protocols. For more information, see Limits.
Before you use NAS volumes, we recommend that you update the CSI plug-in to the latest version.
After a mount target is created, wait until the mount target changes to the Available state.
Do not delete the mount target of a NAS file system before you unmount the NAS file system. Otherwise, an operating system hang issue may occur.
Usage notes
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.NAS is a shared storage service. A persistent volume claim (PVC) that is used to mount a NAS file system can be shared among pods. 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?
Statically provisioned NAS volumes cannot be expanded.
If the securityContext.fsgroup parameter is set in the application template, the kubelet performs the
chmod
orchown
operation after the volume is mounted, which increases the time consumption.NoteFor more information about how to speed up the mounting process when the securityContext.fsgroup parameter is set, see Why does it require a long time to mount a NAS volume?
Mount a statically provisioned NAS volume
You can mount a statically provisioned NAS volume in the ACK console or by using kubectl.
Mount a statically provisioned NAS volume in 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 .
In the upper-right corner of the Persistent Volumes page, click Create.
In the Create PV dialog box, configure the following parameters.
Parameter
Description
PV Type
You can select Cloud Disk, NAS, or OSS. In this example, NAS is selected.
Volume Name
The name of the PV that you want to create. The name must be unique in the cluster. In this example, pv-nas is used.
Capacity
The capacity of the PV. A 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.
Access Mode
You can select ReadWriteMany or ReadWriteOnce. Default value: 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.
Mount Target Domain Name
You can select Select Mount Target to select a mount target or select Custom to enter a mount target. For more information about how to view the domain name of a mount target, see View the domain name of a mount target.
Show Advanced Options
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 set 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 set this parameter, the root directory of the NAS file system is mounted.
If you want to mount an Extreme NAS file system, the subdirectory must be under the /share directory.
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
archiveOnDelete
totrue
, the related PV and NAS file system are renamed after you delete a PVC. They are not deleted together with the PVC.If you set
archiveOnDelete
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 require higher data security, we recommend that you use the Retain mode to prevent data loss caused by user errors.
Mount Options: The optional parameters for mounting a NAS file system, including 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.
Label
Add labels to the PV.
After you complete the configuration, click Create.
Step 2: Create a PVC
In the left-side navigation pane of the details page, choose .
In the upper-right corner of the Persistent Volume Claims page, click Create.
In the Create PVC dialog box, set the following parameters.
Parameter
Description
PVC Type
You can select Cloud Disk, NAS, or OSS. In this example, NAS is selected.
Name
The name of the PVC. The name must be unique in the cluster.
Allocation Mode
In this example, Existing Volumes is selected.
NoteIf no PV is created, you can set Allocation Mode to Create Volume and set the required parameters to create a PV. For more information, see Step 1: Create a PV.
Existing Storage Class
Click Select PV. Find the PV that you want to use and click Select in the Actions column.
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.
Access Mode
The default value is ReadWriteMany. You can also set the value to ReadWriteOnce or ReadOnlyMany.
Click Create.
After the PVC is created, you can view the PVC in the PVCs list. The PVC is bound to the corresponding PV.
Step 3: Create an application
In the left-side navigation pane of the details page, choose .
On the Deployments page, click Create from Image.
Configure the application parameters.
Add Local Storage: You can select HostPath, ConfigMap, Secret, or EmptyDir from the PV Type drop-down list. Then, set the Mount Source and Container Path parameters to mount the volume to a container path. For more information, see Volumes.
Add PVC: You can add cloud volumes.
After the application configuration is completed, click Create.
This example shows how to configure the volume parameters. For more information about other parameters, see Create a stateless application by using a Deployment.
You can add local volumes and cloud volumes.
In this example, a NAS volume is mounted to the /tmp path in the container.
Mount a statically provisioned NAS volume by using kubectl
Statically provisioned NAS volumes
Create a statically provisioned PV.
Create a file named pv-nas.yaml and copy the following content into 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: "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 that you want to add to the PV.
storage
The capacity of the NAS volume.
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.
ImportantReplace 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 View the domain name of a mount target.
path
The subdirectory of the NAS file system that you want to mount. If you want to mount an Extreme NAS file system, the subdirectory must be under the /share directory.
vers
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.
Run the following command to 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 it to the PVC.
Create a file named pvc-nas.yaml and copy the following content into 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
name
The name of the PVC.
accessModes
The access mode of the PV. The default value is
ReadWriteMany
. You can also set the value toReadWriteOnce
orReadOnlyMany
.storage
The capacity claimed by the PVC. The claimed capacity cannot exceed the capacity of the PV that is bound to the PVC.
matchLabels
The labels are used to select a PV and bind it to the PVC.
Run the following command to create a PVC used for static provisioning:
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: nginx 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 that is mounted to the application.
Run the following command to create an application named nas-static and mount the created PVC to the application:
kubectl create -f nas.yaml
Run the following command to query the pods that run the 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
Verify that the NAS file system can be used to persist data
Query the deployed application and the files in the mounted NAS file system.
Run the following command to query the name of 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
Run the following command to query files in the /data path of a pod. The pod
nas-static-5b5cdb85f6-n****
is used as an example:kubectl exec nas-static-5b5cdb85f6-n**** -- ls /data
No output is returned. This indicates that no file exists in the /data path.
Run the following command to create a file named nas in the /data path of the pod
nas-static-5b5cdb85f6-n****
:kubectl exec nas-static-5b5cdb85f6-n**** -- touch /data/nas
Run the following command to query files in the /data path of the pod
nas-static-5b5cdb85f6-n****
:kubectl exec nas-static-5b5cdb85f6-n**** -- ls /data
Expected output:
nas
Run the following command to delete the pod:
kubectl delete pod nas-static-5b5cdb85f6-n****
Open another CLI and run the following command to 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.
Run the following command to query the name of the recreated pod:
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
Run the following command to query files in the /data path of the pod
nas-static-5b5cdb85f6-n****
:kubectl exec nas-static-5b5cdb85f6-n**** -- 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 pods that are created for the application and the files in the mounted NAS file system.
Run the following command to query the pods that are created for the 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
Run the following command to query 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
Run the following command to create a file named nas in the /data path of a pod:
kubectl exec nas-static-5b5cdb85f6-n**** -- touch /data/nas
Run the following command to query files in the /data path of the two pods.
Run the following command to query files in the /data path of the pod
nas-static-5b5cdb85f6-n****
:kubectl exec nas-static-5b5cdb85f6-n**** -- ls /data
Expected output:
nas
Run the following command to query files in the /data path of the pod
nas-static-c5bb4746c-4****
: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
If you want to dynamically resize volumes, use dynamically provisioned NAS volumes. For more information, see Mount a dynamically provisioned NAS volume.
For more information about how to use CNFS to manage NAS file systems, see Use CNFS to manage NAS file systems (recommended) and Use CNFS to manage NAS file systems (recommended).