Apsara File Storage NAS (NAS) is a distributed file system that supports shared access, elastic scaling, high reliability, and high performance. This topic describes how to mount a statically provisioned NAS volume, and how to enable persistent storage and shared storage by using a statically provisioned NAS volume.
Prerequisites
An Alibaba Cloud Container Compute Service (ACS) cluster is created. For more information, see Create an ACS cluster.
NAS is activated and a NAS file system is created. For more information, see Create a NAS file system.
NoteIf 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.
NoteThe 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).
Use scenarios
NAS volumes are suitable for applications that require high disk I/O throughput.
NAS volumes can be used to persist data. The read and write performance of NAS is hither than Object Storage Service (OSS).
NAS volumes can be used to share files among hosts.
Precautions
If a NAS file system is mounted to multiple pods, the data in the file system is shared by the pods. In this case, the application must be able to synchronize data across the pods if the data in the NAS file system is modified by multiple pods.
NoteYou cannot grant permissions to access the
/
directory (root directory) of the NAS file system. The user account and user group to which the directory belongs cannot be modified.You cannot specify the
securityContext.fsgroup
parameter in the application YAML template. This may cause mount failures.You can mount a dynamically provisioned NAS volume in filesystem mode to share the root directory (
/
) of the NAS file system.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.
Create a statically provisioned NAS volume
Use the console
Step 1: View the region and zone of the ACS cluster
Log on to the ACS console. In the left-side navigation pane, click Clusters.
On the Clusters page, select your ACS cluster.
In the left-side navigation pane of the cluster management page, click Cluster Information.
On the Cluster Information page, click the Cluster Resources tab.
Find the virtual private cloud (VPC) and pod vSwitch of the ACS cluster and click them to view details. Record the IDs and names of the VPC and pod vSwitch and the region and zone information.
Step 2: Create a NAS file system and mount target
Log on to the NAS console.
Click Create General-purpose NAS File System in the lower part of the page.
On the General-purpose NAS (Pay-as-you-go) page, configure parameters.
Region: Select the region of the ACS cluster.
Zone: Select the zone of the ACS cluster in Step 1.
Select a storage class.
Protocol Type: Select NFS.
VPC: Select the VPC of the ACS cluster. This parameter requires you to select the name instead of the ID of a VPC.
vSwitch: Select a vSwitch in the preceding zone. This parameter requires you to select the name instead of the ID of a vSwitch.
After the NAS file system is created, choose File System > File System List in the left-side navigation pane. Then, click the NAS file system that you created to view details.
In the left-side navigation pane of the file system details page, click Mount Targets. Then, click Add Mount Target to add a mount target and wait until the mount target enters the Available state.
To create an Extreme NAS file system, you need to first create the file system and log on to the file system to add a mount target. Configure the parameters of the Extreme NAS file system, such as the VPC and vSwitch, as described in the preceding step.
Step 3: Create a PVC
Log on to the ACS console. In the left-side navigation pane, click Clusters.
On the Clusters page, select your ACS cluster.
In the left-side navigation pane of the cluster management page, choose Volumes > Persistent Volume Claims.
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
Valid values: Cloud Disk and NAS. In this example, NAS is selected.
Name
The name of the PVC. The name must be unique within the cluster.
Allocation Mode
Select Use Mount Target Domain Name.
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.
Mount Target Domain Name
Enter the mount target you obtained in Step 2. By default, the root directory (
/
) of the NAS file system is shared.ImportantTo share a subpath or you created an Extreme NAS file system in Step 2, you must use kubectl to set the mount target.
The shared directory of an Extreme NAS file system must start with
/share
, for example,/share
and/share/subdir
.
Click Create.
After the PVC is created, you can find the PVC in the list. The PVC is in the Pending state, which means that the PVC is not used by any pod.
Step 4: Create an application
In the left-side navigation pane of the cluster details page, choose Workloads > Deployments.
On the Deployments tab, click Create from Image.
Configure the Deployment parameters.
The following section describes how to configure the volume parameters. For more information about other parameters, see Create a stateless application by using a Deployment.
You can create volumes that use local storage or cloud storage in ACS clusters.
Add Local Storage: You can select ConfigMap, Secret, or EmptyDir to mount the mount source to a path in containers. For more information, see Volumes.
Add PVC: You can select cloud storage.
In this example, a NAS volume is mounted to the
/tmp
path in a container.Set other parameters and click Create.
After the Deployment is created, you can mount the volume to the pods created by the Deployment.
Use kubectl
Prerequisite: A kubectl client is connected to the ACS cluster. For more information, see Obtain the kubeconfig file of a cluster and use kubectl to connect to the cluster.
Step 1: Create a PVC used for static provisioning.
Create a file named pvc-nas.yaml and copy the following content to the file:
kind: PersistentVolumeClaim apiVersion: v1 metadata: name: pvc-nas annotations: csi.alibabacloud.com/mountpoint: ****.nas.aliyuncs.com csi.alibabacloud.com/mount-options: nolock,tcp,noresvport spec: accessModes: - ReadWriteMany resources: requests: storage: 20Gi storageClassName: alibaba-cloud-nas
Parameter
Description
name
The name of the PVC.
metadata.annotations.csi.alibabacloud.com/mountpoint
The mount target of the NAS file system that you created.
ImportantIf you enter ****.nas.aliyuncs.com, the root directory (
/
) of the NAS file system is shared. If you enter ****.nas.aliyuncs.com:/dir, the/dir
directory of the NAS file system is shared. If the/dir
directory does not exist, the system automatically creates one.metadata.annotations.csi.alibabacloud.com/mount-options
The mount parameter. By default, this parameter is not specified.
accessModes
The access mode of the PVC.
storage
The capacity claimed by the PVC. The claimed capacity cannot exceed the capacity of the PV that is bound to the PVC.
Run the following command to create a PVC used for static provisioning:
kubectl create -f pvc-nas.yaml
Step 2: Create an application named nas-static and mount the PVC to 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-785b747ddf-q**** 1/1 Running 0 32s nas-static-785b747ddf-z**** 1/1 Running 0 32s
Verify that the NAS file system can be used to persist data
Query the pods that run the application and the files in the mounted NAS file system.
Run the following command to query the pods that run the application:
kubectl get pod
Expected output:
NAME READY STATUS RESTARTS AGE nas-static-785b747ddf-q**** 1/1 Running 0 32s nas-static-785b747ddf-z**** 1/1 Running 0 32s
Run the following command to query files in the
/data
path of a pod. In this example, the pod namednas-static-785b747ddf-q****
is queried.kubectl exec nas-static-785b747ddf-q**** -- 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 thenas-static-785b747ddf-q****
pod:kubectl exec nas-static-785b747ddf-q**** -- touch /data/nas
Run the following command to query files in the
/data
path of thenas-static-5b5cdb85f6-n****
pod:kubectl exec nas-static-785b747ddf-q**** -- ls /data
Expected output:
nas
Run the following command to delete the pod:
kubectl delete pod nas-static-785b747ddf-q****
Open another CLI and run the following command to view how the pod is deleted and recreated:
kubectl get pod -w -l app=nas-static
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-785b747ddf-6**** 1/1 Running 0 25s nas-static-785b747ddf-z**** 1/1 Running 0 2m
Run the following command to query files in the
/data
path of thenas-static-785b747ddf-6****
pod:kubectl exec nas-static-785b747ddf-6**** -- ls /data
Expected output:
nas
If the
nas
file still exists, this means that the NAS file system can be used to persist data.
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-785b747ddf-6**** 1/1 Running 0 25s nas-static-785b747ddf-z**** 1/1 Running 0 2m
Run the following command to query files in the
/data
path of each pod:kubectl exec nas-static-785b747ddf-6**** -- ls /data kubectl exec nas-static-785b747ddf-z**** -- ls /data
Run the following command to create a file named
nas
in the/data
path of a pod:kubectl exec nas-static-785b747ddf-6**** -- touch /data/nas
Run the following command to query files in the
/data
path of each pod:Run the following command to query files in the
/data
path of thenas-static-785b747ddf-6****
pod:kubectl exec nas-static-785b747ddf-6**** -- ls /data
Expected output:
nas
Run the following command to query files in the
/data
path of thenas-static-785b747ddf-z****
pod:kubectl exec nas-static-785b747ddf-z**** -- 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.