A NAS volume is a distributed file system that provides shared access, scalability, high reliability, and high performance. This topic describes how to use a statically provisioned Alibaba Cloud NAS volume to implement persistent and shared storage.
Prerequisites
An ACK Serverless cluster is created. For more information, see Create an ACK Serverless 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, you must configure the encryption type when you create the NAS file system.
A NAS mount target is created. For more information, see Manage mount targets.
The NAS mount target must be in the same VPC as the cluster nodes.
You have connected to the cluster using kubectl. For more information, see Obtain the kubeconfig file of a cluster and use kubectl to connect to the cluster.
Scenarios
Applications that have high requirements for disk I/O.
You can implement file sharing across hosts. For example, you can use a NAS volume as a file server.
Considerations
When you use an Extreme NAS file system, the
pathof the volume must be a subdirectory of /share. For example, you can set the subdirectory of the NAS file system that is mounted to a pod to /share/path1.A NAS file system can be mounted to multiple pods at the same time. In this case, the pods may modify the same data. Your application must be able to synchronize data.
NoteYou cannot modify the permissions, owner, or group of the / directory of a NAS file system.
If you set the securityContext.fsgroup parameter in the application template, Kubelet runs the
chmodorchownoperation after the volume is mounted. This prolongs the mount time.NoteIf you have set the securityContext.fsgroup parameter and want to reduce the mount time, see The mount time of a NAS volume is prolonged.
Use a statically provisioned NAS volume in the console
Step 1: Create a Persistent Volume (PV)
Log on to the ACK console. In the left navigation pane, click Clusters.
On the Clusters page, find the cluster that you want to manage and click the name of the cluster or click Details in the Actions column. The details page of the cluster appears.
In the left-side navigation pane of the cluster details page, choose .
On the Persistent Volumes page, click Create in the upper-left corner.
In the Create PV dialog box, set the parameters.
Parameter
Description
PV Type
In this example, select NAS.
Name
The name of the PV. The name must be unique in the cluster. In this example, pv-nas is used.
Capacity
The capacity of the PV. Note that NAS file systems do not have a capacity limit. This parameter specifies the capacity of the PV, not the capacity limit of the NAS file system.
Access Mode
Select ReadWriteMany or ReadWriteOnce. The default value is ReadWriteMany.
Mount Target Domain Name
You can Select Mount Target or specify a Custom mount target as the mount address for the cluster to access the NAS file system.
Advanced Options (Optional)
Mount Path
Subdirectory in the NAS file system to mount.
If not set, defaults to root (
/for General-purpose NAS,/sharefor Extreme NAS).If the directory doesn't exist, it will be created.
NoteFor Extreme NAS, paths must start with
/share, such as/share/data.Reclaim Policy
The default value is Retain. This indicates that when a PVC is deleted, the related PV and NAS file system are retained and can only be manually deleted.
Mount Options
NAS mount parameter, including NFS protocol version. We recommend using NFS v3 protocol, because Extreme NAS only supports NFS v3. For more information about the NFS protocol, see NFS protocol.
Label
Add labels to the PV.
After you set the parameters, click OK.
Step 2: Create a Persistent Volume Claim (PVC)
In the left-side navigation pane of the details page, choose .
On the Persistent Volume Claims page, click Create in the upper-left corner.
In the Create PVC dialog box, set the parameters.
Parameter
Description
PVC Type
In this example, select NAS.
Name
The name of the PVC. The name must be unique in the cluster.
Allocation Mode
Select Existing Volumes.
NoteIf no PV is created, you can set Allocation Mode to Create Volume and set the parameters to create a PV. For more information, see Create a PV.
Existing Volumes
Click Select PV, find the target PV, and then 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.
Click OK.
After the PVC is created, you can view it in the list. The status of the PVC changes to Bound, which indicates that it is bound to the corresponding PV.
Step 3: Create an application
In the navigation pane on the left of the cluster details page, go to .
On the Deployments page, click Create From Image.
Configure the parameters of the application. After doing so, click Create.
The following table describes the key parameters. Use default settings for other parameters. For more information, see Create a stateless application 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.
nas-test
Replicas
Number of pod replicas.
2
Container
Image Name
Container image.
anolis-registry.cn-zhangjiakou.cr.aliyuncs.com/openanolis/nginx:1.14.1-8.6
Required Resources
CPU and memory.
0.25 Core, 512 MiB
Volume
Click Add PVC and configure the parameters.
Mount Source: Select the PVC that 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
View the application deployment status.
On the Deployments page, click the name of the application.
On the Pods tab, confirm pods are in the Running state.
Use a statically provisioned NAS volume using kubectl
Run the following command to create a statically provisioned PV.
kubectl create -f pv-nas.yamlThe following code provides a sample YAML file for creating a statically provisioned PV.
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 volumeAttributes: server: "2564f4****-ysu87.cn-shenzhen.nas.aliyuncs.com" path: "/csi" mountOptions: - nolock,tcp,noresvport - vers=3Parameter
Description
name
The name of the PV.
labels
The labels of the PV.
storage
The available capacity of the NAS file system.
accessModes
The access mode.
driver
The type of the driver. In this example, the value is
nasplugin.csi.alibabacloud.com, which indicates that the Alibaba Cloud NAS CSI plug-in is used.volumeHandle
The unique ID of the PV. If you want to use multiple PVs at the same time, the value of this parameter must be unique for each PV.
server
The NAS mount target.
path
The subdirectory to mount. For an Extreme NAS file system, the subdirectory must be a subdirectory of /share.
vers
The version number of the NFS protocol that is used to mount the NAS volume. We recommend that you use v3. Extreme NAS file systems support only v3.
Run the following command to create a statically provisioned PVC.
Create a PVC for the NAS file system. Use the
selectorfield to filter PVs and bind the PVC to a specific PV.kubectl create -f pvc-nas.yamlThe following code provides a sample YAML file for creating a statically provisioned PVC.
kind: PersistentVolumeClaim apiVersion: v1 metadata: name: pvc-nas spec: accessModes: - ReadWriteMany resources: requests: storage: 5Gi selector: matchLabels: alicloud-pvname: pv-nasParameter
Description
name
The name of the PVC.
accessModes
The access mode.
storage
The capacity requested by the application. The value cannot be greater than the total capacity of the PV.
matchLabels
The labels of the PV to associate.
Run the following command to create an application named nas-static and mount the PVC.
kubectl create -f nas.yamlThe following code provides a sample nas.yaml file for creating 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: registry.cn-hangzhou.aliyuncs.com/acs-sample/nginx:latest ports: - containerPort: 80 volumeMounts: - name: pvc-nas mountPath: "/data" volumes: - name: pvc-nas persistentVolumeClaim: claimName: pvc-nasParameter
Description
mountPath
The path to which the NAS volume is mounted in the container.
claimName
The name of the PVC to bind.
Run the following command to view pod information.
kubectl get podExpected 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 the persistence of the NAS volume
View the deployed application and NAS files.
Run the following command to view the names of the pods for the deployed application.
kubectl get podExpected output:
NAME READY STATUS RESTARTS AGE nas-static-5b5cdb85f6-n**** 1/1 Running 0 32s nas-static-c5bb4746c-4**** 1/1 Running 0 32sRun the following command to view the files in the /data path of one of the application pods. This topic uses the pod named
nas-static-5b5cdb85f6-n****as an example.kubectl exec nas-static-5b5cdb85f6-n**** -- ls /dataThe command returns no output, which 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
nas-static-5b5cdb85f6-n****pod.kubectl exec nas-static-5b5cdb85f6-n**** -- touch /data/nasRun the following command to view the files in the /data path of the
nas-static-5b5cdb85f6-n****pod.kubectl exec nas-static-5b5cdb85f6-n**** -- ls /dataExpected output:
nasRun the following command to delete the pod.
kubectl delete pod nas-static-5b5cdb85f6-n****In another window, run the following command to monitor the deletion of the pod and the creation of a new pod by Kubernetes.
kubectl get pod -w -l app=nginxVerify that the file created in the NAS volume still exists after the pod is deleted.
Run the following command to view the name of the pod that is recreated by Kubernetes.
kubectl get podExpected output:
NAME READY STATUS RESTARTS AGE nas-static-5b5cdb85f6-n**** 1/1 Running 0 32s nas-static-c5bb4746c-4**** 1/1 Running 0 32sRun the following command to view the files in the /data path of the
nas-static-5b5cdb85f6-n****pod.kubectl exec nas-static-5b5cdb85f6-n**** -- ls /dataExpected output:
nasThe nas file still exists, which indicates that the data in the NAS volume is persistent.
Verify the shared storage of the NAS volume
View the pods where the application is deployed and the NAS files.
Run the following command to view the names of the pods where the application is deployed.
kubectl get podExpected output:
NAME READY STATUS RESTARTS AGE nas-static-5b5cdb85f6-n**** 1/1 Running 0 32s nas-static-c5bb4746c-4**** 1/1 Running 0 32sRun the following command to view 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
Run the following command to create a file named nas in the /data path of one of the pods.
kubectl exec nas-static-5b5cdb85f6-n**** -- touch /data/nasRun the following command to view the files in the /data path of the two pods.
Run the following command to view the files in the /data path of the pod named
nas-static-5b5cdb85f6-n****.kubectl exec nas-static-5b5cdb85f6-n**** -- ls /dataExpected output:
nasRun the following command to view the files in the /data path of the pod named
nas-static-c5bb4746c-4****.kubectl exec nas-static-c5bb4746c-4**** -- ls /dataExpected output:
nasIf the file created in the /data path of one pod also exists in the /data path of the other pod, it indicates that the two pods share the same NAS volume.