An Apsara File Storage NAS volume is a distributed file system that provides shared access, elastic scalability, high reliability, and high performance, making it ideal for scenarios such as big data analytics, data sharing, web applications, and log storage. You can use the CSI plugin to create a PersistentVolume and a PersistentVolumeClaim from an existing Apsara File Storage NAS file system. You can then mount the volume to a workload for persistent and shared storage.
-
Static volume: You must create a PersistentVolume in advance to represent an existing storage resource, such as an Apsara File Storage NAS file system. An application then creates a PersistentVolumeClaim to request a matching PersistentVolume. This method is commonly used to manage existing storage resources. By default, the bound PersistentVolumeClaim does not support online expansion.
-
Dynamic volume: You do not need to create a PersistentVolume in advance. When an application creates a PersistentVolumeClaim, the system automatically creates a new storage volume and its corresponding PersistentVolume based on the StorageClass specified in the PersistentVolumeClaim. This mode is more flexible and supports volume expansion.
Prerequisites
-
Your existing Apsara File Storage NAS file system must meet the following requirements. Otherwise, create a file system or use dynamic NAS volumes.
-
The protocol type is NFS. You cannot mount an Apsara File Storage NAS file system that uses the SMB protocol.
-
The mount target and the cluster nodes must be in the same VPC, and the mount target's Status must be Available. If you need to add a mount target, see Manage mount targets.
You can mount an Apsara File Storage NAS file system only to pods within the same VPC. Cross-VPC mounting is not supported. However, you can mount a file system across availability zones within that VPC.
NoteTo encrypt data in a NAS volume, configure the encryption type when you create the Apsara File Storage NAS file system.
-
Usage notes
-
Apsara File Storage NAS provides shared storage, which means you can mount a single NAS volume to multiple pods. This can lead to concurrent write operations from multiple pods, so your application must ensure data consistency.
For more information about the limitations on concurrent writes to Apsara File Storage NAS, see How do I prevent exceptions that might occur when multiple processes or clients write to the same log file concurrently? and How do I resolve the latency issue when writing data to an NFS file system?
-
If you configure the
securityContext.fsgroupparameter in an application template, kubelet executeschmodorchownoperations after the volume is mounted, which increases the mount time. If you have configured thesecurityContext.fsgroupparameter and need to reduce the mount time, see Long mount times for NAS volumes for more information. -
After you mount a NAS volume, do not delete the Apsara File Storage NAS mount target. This makes the system unresponsive.
Mount a static NAS volume (kubectl)
Step 1: Create a PersistentVolume
-
Obtain the kubeconfig file of a cluster and use kubectl to connect to the cluster.
-
Create a file named pv-nas.yaml that contains the following content.
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 # Must be the same as the PersistentVolume name. volumeAttributes: server: "0c47****-mpk25.cn-shenzhen.nas.aliyuncs.com" # The address of the NAS mount target. The VPC of the mount target must be the same as the VPC of the cluster. path: "/csi" # The subdirectory to mount. mountOptions: - nolock,tcp,noresvport - vers=3Parameter
Description
nameThe name of the PersistentVolume.
labelsThe labels of the PersistentVolume.
storageThe capacity of the PersistentVolume.
ImportantThis setting does not limit the actual available capacity of a NAS volume. The specifications of the Apsara File Storage NAS file system determine its capacity. See General-purpose NAS and Extreme NAS to check the available capacity.
accessModesThe access mode. The default value is
ReadWriteMany.ReadWriteOnceandReadOnlyManyare also supported.driverThe type of the driver. Set this parameter to
nasplugin.csi.alibabacloud.comto use the Alibaba Cloud NAS CSI plugin.volumeHandleA unique identifier for the PersistentVolume. This value must match the PersistentVolume name and be unique across all PersistentVolumes in the cluster.
serverThe address of the Apsara File Storage NAS mount target. The VPC of the mount target must be the same as the VPC of the cluster.
To find the address of the mount target, see Manage mount targets.
pathThe subdirectory of the Apsara File Storage NAS file system to mount.
-
If you do not set this parameter, the root directory is mounted by default.
-
If the directory does not exist in the Apsara File Storage NAS file system, the system automatically creates it before mounting.
NoteThe root directory for a General-purpose NAS file system is
/. The root directory for an Extreme NAS file system is/share. When you mount a subdirectory of an Extreme NAS file system, thepathmust start with/share, such as/share/data.mountOptionsThe mount parameters for the Apsara File Storage NAS file system, including the NFS protocol version. We recommend that you use NFSv3. Extreme NAS file systems support only NFSv3. For more information about the NFS protocol, see NFS protocols.
-
-
Create the PersistentVolume.
kubectl create -f pv-nas.yaml -
View the PersistentVolume.
kubectl get pvExpected output:
NAME CAPACITY ACCESS MODES RECLAIM POLICY STATUS CLAIM STORAGECLASS VOLUMEATTRIBUTESCLASS REASON AGE pv-nas 5Gi RWX Retain Available <unset> 25s
Step 2: Create a PVC
Save the following YAML template as pvc-nas.yaml:
kind: PersistentVolumeClaim apiVersion: v1 metadata: name: pvc-nas spec: accessModes: - ReadWriteMany resources: requests: storage: 5Gi selector: matchLabels: alicloud-pvname: pv-nasParameter
Description
nameName of the PVC.
accessModesMust match the PV’s access mode. Default:
ReadWriteMany. You can also set the value toReadWriteOnceorReadOnlyMany.storageRequested storage capacity. Cannot exceed the PV's capacity.
ImportantThe actual available capacity is determined by the NAS file system specifications, not this value. See General-purpose NAS and Extreme NAS for details.
matchLabelsLabels used to bind the PVC to the PV.
Create the PVC:
kubectl create -f pvc-nas.yamlView the PVC:
kubectl get pvcExpected output:
NAME STATUS VOLUME CAPACITY ACCESS MODES STORAGECLASS VOLUMEATTRIBUTESCLASS AGE pvc-nas Bound pv-nas 5Gi RWX <unset> 5s
Step 3: Create an application and mount NAS
Save the following YAML as nas.yaml:
apiVersion: apps/v1 kind: Deployment metadata: name: nas-test 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-nasParameter
Description
mountPathContainer path where the NAS volume is mounted.
claimNameName of the PVC to bind.
Deploy the application:
kubectl create -f nas.yamlCheck pod status:
kubectl get pod -l app=nginxExpected output:
NAME READY STATUS RESTARTS AGE nas-test-****-***a 1/1 Running 0 32s nas-test-****-***b 1/1 Running 0 32s
Verify the shared storage and persistent storage features of NAS
The Deployment created in the preceding example provisions two pods and mounts a NAS file system to the pods. You can use the following methods to verify this:
Create a file in one pod and view the file from the other pod to verify shared storage.
Recreate the Deployment. Then, check whether data stored in the file system exists in the newly created pod to verify persistent storage.
View the pod information.
kubectl get pod | grep nas-testSample result:
nas-test-*****a 1/1 Running 0 40s nas-test-*****b 1/1 Running 0 40sVerify shared storage.
Create a file in a pod.
In this example, the
nas-test-*****apod is used:kubectl exec nas-test-*****a -- touch /data/test.txtView the file from the other pod.
In this example, the
nas-test-*****bpod is used:kubectl exec nas-test-*****b -- ls /dataExpected output shows that the newly created file
test.txtis shared:test.txt
Verify persistent storage.
Recreate the Deployment.
kubectl rollout restart deploy nas-testWait until the pods are recreated.
kubectl get pod | grep nas-testSample result:
nas-test-*****c 1/1 Running 0 67s nas-test-*****d 1/1 Running 0 49sLog on to a recreated pod and check whether the file still exists in the file system.
In this example, the
nas-test-*****cpod is used:kubectl exec nas-test-*****c -- ls /dataThe following output shows that the file still exists in the NAS file system and can be accessed from the mount directory in the recreated pod.
test.txt
FAQ
If you encounter issues when mounting or using NAS volumes, see the following troubleshooting topics.