You can use the FlexVolume plug-in provided by Alibaba Cloud to mount Apsara File Storage NAS (NAS) file systems to Container Service for Kubernetes (ACK) clusters. This topic describes how to mount a statically provisioned NAS volume.
chownoperation after the volume is mounted, which increases the time consumption.
You can mount a NAS file system by using a PV and a PVC.
- Create a PV. You can create a PV in the ACK console or by using a YAML file.
- Create a PV by using a YAML file.
Use the following nas-pv.yaml file to create a PV:
apiVersion: v1 kind: PersistentVolume metadata: name: pv-nas spec: capacity: storage: 5Gi storageClassName: nas accessModes: - ReadWriteMany flexVolume: driver: "alicloud/nas" options: server: "0cd8b4a576-u****.cn-hangzhou.nas.aliyuncs.com" path: "/k8s" vers: "3" options: "nolock,tcp,noresvport"
- Create a PV in the ACK console.
- Log on to the ACK console.
- In the left-side navigation pane of the ACK console, click Clusters.
- On the Clusters page, find the cluster that you want to manage. Then, click the name of the cluster or click Details in the Actions column.
- In the left-side navigation pane of the cluster details page, choose .
- On the Volumes page, click Create in the upper-right corner of the page.
- In the Create PV dialog box, set the parameters.
Parameter Description PV Type In this example, NAS is selected. Volume 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. Volume Plug-in In this example, Flexvolume is selected. For more information about volume plug-ins, see Differences between the CSI and FlexVolume plug-ins. Capacity The capacity of the PV that you want to create. The capacity of the PV cannot exceed that of the NAS file system to be mounted. Access Mode Default value: ReadWriteMany. Mount Target Domain Name The domain name of the mount target that is used to mount the NAS file system to the cluster. For more information about how to manage the mount targets of a NAS file system, see Manage mount targets. Subdirectory Enter a subdirectory in the NAS file system. The subdirectory must start with a forward slash (/). If this parameter is set, the PV will be mounted to the specified 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 specify a subdirectory of an Extreme NAS file system, the subdirectory must start with /share.
Permissions The access permissions on the mounted directory. For example, you can set this parameter to 755, 644, or 777.Note
If the mounted directory is a subdirectory, this parameter is optional.
- You can set access permissions only on subdirectories.
- If the mounted directory stores a large number of files, we recommend that you do not set this parameter. Otherwise, the process of running the chmod command may require an excessive amount of time.
- If you do not set this parameter, the original permissions on the mounted directory are used.
- Take note of the following items when you set the permissions:
- For FlexVolume versions earlier than V184.108.40.206-8d3b7e7-aliyun, use the recursive mode when you configure permission settings. The permissions on all files and directories under the mounted directory will be modified.
- For FlexVolume V220.127.116.11-8d3b7e7-aliyun and later, set the chmod (Change Mode) parameter to configure permission settings.
chmod (Change Mode) The change mode of access permissions. Valid values: Non-recursive and Recursive.
- Non-recursive: The permission changes apply only to the mounted directory. The subdirectories and files in the mounted directory are not affected.
- Recursive mode: The permission changes apply to the mounted directory, and the subdirectories
and files in the mounted directory.
Note If you select the recursive mode for a mounted directory that contains a large number of files, the process of running the chmod command may require an excessive amount of time. The mount or unmount operation may fail. Exercise caution when you set this parameter.
Version The version of the NFS protocol. We recommend that you use NFSv3. Extreme NAS file systems support only NFSv3. Labels Add labels to the PV.
- Click Create.
- Create a PV by using a YAML file.
- Create a PVC. Use the following nas-pvc.yaml file to create a PVC:
apiVersion: v1 kind: PersistentVolumeClaim metadata: name: pvc-nas spec: accessModes: - ReadWriteMany storageClassName: nas resources: requests: storage: 5Gi
- Create a pod. Use the following nas-pod.yaml file to create a pod:
apiVersion: apps/v1 kind: Deployment metadata: name: nas-static labels: app: nginx spec: replicas: 1 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