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.
You want to share files across hosts. For example, you want to use a NAS file system as a file server.
Consideration
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.
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.
Note
You 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.
If the securityContext.fsgroup parameter is set in the application template, kubelet performs the chmod or chown operation after the volume is mounted. This increases the mounting time.
Mount a statically provisioned NAS volume in the 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 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 Volumes > Persistent Volumes.
In the upper-right corner of the Persistent Volumes page, click Create.
In the Create PV dialog box, configure the following parameters.
Parameter
Description
Parameter
Description
PV Type
You can select Cloud Disk or NAS. In this example, NAS is selected.
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.
Mount Target Domain Name
You can select Select Mount Target to select a mount target or select Custom to enter a mount target.
Show Advanced Options
Subdirectory: the subdirectory of the NAS file system that you want to mount. The subdirectory must start with a forward slash (/). After you set this parameter, the PV is mounted to the 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.
Version: the version of the PV.
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 Volumes > Persistent Volume Claims.
In the upper-right corner of the Persistent Volume Claims page, click Create.
In the Create PVC dialog box, configure the required parameters.
Parameter
Description
Parameter
Description
PVC Type
You can select Cloud Disk or NAS. In this example, NAS is selected.
Name
The name of the persistent volume claim (PVC). The name must be unique in the cluster.
Allocation Mode
In this example, Existing Volumes is selected.
Note
If 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 Create a PV.
Existing Volumes
Click Select PV. Find the PV that you want to use and click Select in the Actions column.
Capacity
The capacity claimed by the PVC.
Note
The capacity claimed by the PVC cannot exceed the capacity of the PV that is bound to the PVC.
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 Workloads > Deployments.
In the upper-right corner of the Deployments page, click Create from Image.
You can configure local volumes and cloud volumes for ACK Serverless clusters.
Add Local Storage: You can select 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.
In this example, a NAS volume is mounted to the /tmp path in the container.
Set other parameters and click Create.
After the application is created, you can use the volume to store application data.
Mount a statically provisioned NAS volume by using kubectl
Run the following command to create a statically provisioned PV:
kubectl create -f pv-nas.yaml
The following YAML template provides an example on how to create a statically provisioned PV:
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. If multiple PVs are used, the identifier of each PV must be unique.
server
The mount target of the NAS file system.
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 Network File System (NFS) protocol. We recommend that you use NFSv3. Extreme NAS file systems support only NFSv3.
Run the following command to create a PVC for the statically provisioned PV:
When you create a PVC of the NAS type, set the selector parameter to configure how to select a PV and bind it to the PVC.
kubectl create -f pvc-nas.yaml
The following YAML template provides an example on how to create a PVC used for static provisioning:
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 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
If a file created under the /data path of a pod exists under the /data path of another pod, it indicates that data in the NAS file system is shared by these two pods.