This topic explains how to mount an Alibaba Cloud Network Attached Storage (NAS) volume to pods in a Container Service for Kubernetes (ACK) cluster using static provisioning. Static provisioning lets you connect pods to an existing NAS file system for persistent, shared storage across multiple pods simultaneously.
Prerequisites
ACK Serverless cluster has been created. For more information, see Create an ACK Serverless cluster.
A NAS file system has been created. For more information, see Create a file system.
If you need to encrypt data in the NAS PersistentVolume (PV), configure the encryption type when creating the NAS file system.
A NAS mount point has been created. For more information, see Manage mount targets.
The NAS mount point must be in the same VPC as the cluster nodes.
kubectl connected to the cluster. For more information, see Obtain a kubeconfig file and connect to a cluster by using kubectl
Use cases
Applications with high disk I/O requirements.
Supports cross-host file sharing, for example, as a file server.
Notes
When using an Extreme NAS file system, the
pathconfigured for the PersistentVolume (PV) must use /share as the parent directory. For example, the NAS file system subdirectory mounted by a Pod can be set to /share/path1.NAS supports simultaneous mounting by multiple Pods. In this case, multiple Pods may modify the same data concurrently, and the application must implement data synchronization on its own.
NoteThe / directory in NAS storage does not support modifying permissions, ownership, or group.
If you configure the securityContext.fsgroup parameter in an application template, Kubelet will perform
chmodorchownoperations after the PersistentVolume (PV) is mounted, which increases the mount time.NoteIf the securityContext.fsgroup parameter has been configured and you need to reduce the mount time, see NAS volume FAQ.
Mount a NAS volume using the console
Step 1: Create a PV
Log on to the ACK console. In the left navigation pane, click Clusters.
On the Cluster List page, click the name of the destination cluster or click Details in the Actions column.
In the left navigation pane of the cluster management page, choose .
On the Persistent Volumes page, click Create in the upper-right corner.
In the Create PV dialog box, configure the parameters.
Parameter
Note
PV Type
In this example, NAS is selected.
Name
The name of the PersistentVolume (PV) to be created. The PV name must be unique within the cluster. In this example, the name is pv-nas.
Capacity
The capacity of the PersistentVolume (PV) to be created. Note that the NAS file system itself does not impose usage limits. This is not a quota on the NAS file system, but a capacity declaration for the PV being created.
Access Mode
Select ReadWriteMany and ReadWriteOnce. The default value is ReadWriteMany.
Mount Target Domain Name:
You can define the mount address of the cluster at the NAS mount point using either Select Mount Target or Custom.
Advanced Options (Optional)
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
Retain (default): When the PVC is deleted, the PV and NAS files are not deleted. You must manually delete them.
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.Labels
Add labels to this PersistentVolume (PV).
After configuring the parameters, click Create.
Step 2: Create a PVC
In the left navigation pane of the cluster management page, choose .
On the Persistent Volume Claims page, click Create in the upper-right corner.
In the Create PVC dialog box that appears, fill in the parameters.
Parameter
Note
PVC Type
In this example, NAS is selected.
Name
The name of the PersistentVolumeClaim (PVC) to be created must be unique within the cluster.
Allocation Mode
Select an existing PersistentVolume (PV).
NoteIf no PV has been created, you can set Allocation Mode to Create PV to configure the parameters for creating a PV. For more information, see Create a PV.
Existing Volumes
Click Select PV, then in the Actions column to the right of the target PV, click Select Node to select the PV.
Capacity
The capacity of the PersistentVolume (PV) to be created.
NoteThe capacity of the PersistentVolumeClaim (PVC) to be created cannot exceed the capacity of the PersistentVolume (PV) to be mounted.
Click Create.
After the PersistentVolumeClaim (PVC) is created, you can see it in the list, and it is already bound to the corresponding PersistentVolume (PV).
Step 3: Create an application
-
On the Clusters page, click the name of your cluster. In the left navigation pane, click .
On the Deployments page, click Create from Image and configure the application parameters.
The following table describes the main parameters. You can keep the default values for other parameters. For more information, see Create a stateless Deployment.
Category
Parameter
Description
Basic Information
Application Name
The name of the Deployment.
Replicas:
The number of replicas for the Deployment.
This setup lets you verify the shared storage feature of NAS.
Container
Image Name
The address of the application image.
Required Resources
The required vCPU and memory resources.
Volume
Click Add PVC and configure the parameters.
Mount Source: Select the PVC that you created earlier.
Container Path: The path within the container to mount the NAS file system, such as
/data.
When the deployment finishes, go to the Deployments page and click the application's name. On the Pods tab, verify that the Pods are in the Running state.
Mount a NAS volume using kubectl
Run the following command to create a static PV.
kubectl create -f pv-nas.yamlThe following is a sample YAML file for creating a static 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
Note
name
The name of the PV.
labels
Set labels for the PV.
storage
The available capacity of NAS.
accessModes
Configure the access mode.
driver
The driver type. In this example, the value is
nasplugin.csi.alibabacloud.com, indicating that the Alibaba Cloud NAS CSI plugin is used.volumeHandle
Configure a unique identifier for the PV. If multiple PVs are used simultaneously, this value must be different for each PV.
server
NAS mount point.
path
Mount subdirectory. For Extreme NAS, /share must be used as the parent directory.
vers
The NFS protocol version for mounting the NAS PersistentVolume (PV). v3 is recommended. Extreme NAS only supports v3.
Run the following command to create a static PVC.
Create a NAS PersistentVolumeClaim (PVC) and use
selectorto filter PVs, precisely configuring the binding between the PVC and PV.kubectl create -f pvc-nas.yamlThe following is a sample YAML file for creating a static PVC.
kind: PersistentVolumeClaim apiVersion: v1 metadata: name: pvc-nas spec: accessModes: - ReadWriteMany resources: requests: storage: 5Gi selector: matchLabels: alicloud-pvname: pv-nasParameter
Note
name
The name of the PVC.
accessModes
Configure the access mode.
storage
Declare the application usage, which cannot exceed the total capacity of the PersistentVolume (PV).
matchLabels
Enter the PV label to associate with the PV.
Run the following command to create an application named nas-static and mount the PVC.
kubectl create -f nas.yamlThe following is 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
Note
mountPath
The mount path of NAS in the container.
claimName
The name of the PVC, used to bind the PVC.
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 persistent storage of NAS
View the deployed application and NAS files.
Run the following command to view the name of 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 under the /data path of any application. In this example, the Pod named
nas-static-5b5cdb85f6-n****is used.kubectl exec nas-static-5b5cdb85f6-n**** -- ls /dataNo output is returned, indicating that there are no files under the /data path.
Run the following command to create a file nas under the /data path of the Pod named
nas-static-5b5cdb85f6-n****.kubectl exec nas-static-5b5cdb85f6-n**** -- touch /data/nasRun the following command to view the files under 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 delete the Pod.
kubectl delete pod nas-static-5b5cdb85f6-n****At the same time, in another window, run the following command to view the process of Pod deletion and Kubernetes rebuilding the Pod.
kubectl get pod -w -l app=nginxVerify whether the files created in NAS still exist after the Pod is deleted.
Run the following command to view the name of the Pod rebuilt 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 under the /data path of the Pod named
nas-static-5b5cdb85f6-n****.kubectl exec nas-static-5b5cdb85f6-n**** -- ls /dataExpected output:
nasThe nas file still exists, indicating that NAS data can be stored persistently.
Verify shared storage
View the Pods where the deployed application runs and the NAS files.
Run the following command to view the names of the Pods where the application runs.
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 under the /data path of the 2 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 nas under the /data path of any Pod.
kubectl exec nas-static-5b5cdb85f6-n**** -- touch /data/nasRun the following command to view the files under the /data path of the 2 Pods.
Run the following command to view the files under 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 under the /data path of the Pod named
nas-static-c5bb4746c-4****.kubectl exec nas-static-c5bb4746c-4**** -- ls /dataExpected output:
nasIf the file created under the /data path of any Pod is present under the /data path of both Pods, it indicates that the two Pods share the same NAS.