You can use the Flexvolume plug-in provided by Alibaba Cloud to use Apsara File Storage NAS in Container Service.
- server: The mount target of the NAS volume.
- path: The mounted directory in the NAS file system. You can specify a sub-directory as a volume. If no sub-directory exists, the system automatically creates and mounts a sub-directory. To specify a directory in a NAS Extreme file system, the directory must start with /share.
- vers: The version of the NFS protocol. Version 3 and 4.0 are supported. Default is version 3, which is also the recommended version. NAS Extreme file systems support NFS v3 only.
- mode: The access permissions on the mounted directory. If the root directory of the NAS file system is specified as the mounted directory, you cannot modify the access permissions. If you set the mode parameter for a directory that stores a large amount of data, the process of mounting the directory to a cluster may take an excessive amount of time or even fail.
- options: The mount parameter. If not specified, the default values are
nolock,tcp,noresvportin version 3 and
noresvportin version 4.0.
Directly as volumes
Use a nas-deploy.yaml file to create pods.
- Create the nas-deploy.yaml file with the following content.
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: nas1 mountPath: "/data" volumes: - name: "nas1" flexVolume: driver: "alicloud/nas" options: server: "0cd8b4a576-grs79.cn-hangzhou.nas.aliyuncs.com" path: "/k8s" vers: "3" options: "nolock,tcp,noresvport"
- Run the following command to create pods:
kubectl apply -f nas-deploy.yaml
Through PVs and PVCs
- Create a PV
You can create a PV through the 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-uih75.cn-hangzhou.nas.aliyuncs.com" path: "/k8s" vers: "3" options: "nolock,tcp,noresvport"
- Create a PV through the console
- Log on to the Container Service console.
- In the left-side navigation pane, click Clusters.
- On the Clusters page, find the target cluster and click Manage in the Actions column.
- In the left-side navigation pane, choose Persistent Volumes. The PVs and PVCs page appears.
- On the Persistent Volumes tab, click Create in the upper-right corner.
- In the Create PV dialog box, set the following parameters.
- PV Type: In this example, select NAS.
- Volume Name: The name of the PV. The name must be unique in the cluster. In this example, enter pv-nas.
- Capacity: The capacity of the PV. The capacity of the PV cannot exceed that of the NAS file system.
- Access Mode: The default mode is ReadWriteMany.
- Mount Target Domain Name: Specify the domain of the mount target that is used to mount the NAS file system to the cluster.
- Subdirectory: Enter a sub-directory in the NAS file system. The sub-directory must start with
a forward slash (/). If this parameter is set, the PV will be mounted to the sub-directory.
- If the specified sub-directory does not exist, the system automatically creates this sub-directory.
- This parameter is optional. The root directory of the NAS file system is mounted by default.
- To specify a sub-directory in a NAS Extreme file system, the sub-directory must start with /share.
- Permissions: Set the access permissions on the mounted directory. For example, 755, 644, or 777.
You can set access permissions on sub-directories only.
We recommend that you do not set this parameter when the mounted directory contains a large number of files. Otherwise, it may take a long time to run the chmod command.If the mounted directory is a sub-directory of the NAS file system, the Permissions parameter is optional.
- By default, the original permissions are used.
- Note the following points when you set the permissions:
- For Flexvolume versions earlier than v22.214.171.124-8d3b7e7-aliyun, use the recursive mode when you change permission settings. The permissions on all files and directories under the mounted directory will be changed.
- For Flexvolume v126.96.36.199-8d3b7e7-aliyun and later versions, configure the chmod (Change Mode) parameter to define how permission changes are applied.
- chmod (Change Mode): Define how permission changes are applied. Currently, the non-recursive and recursive
modes are supported.
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 take an excessive amount of time. The mount or unmount operation may fail. Exercise caution when you perform this operation.
- Non-recursive mode: The permission change only takes effect on the mounted directory. The sub-directories and included files are not affected.
- Recursive mode: The permission change takes effect on the mounted directory, the sub-directories, and included files.
- Version: The version of the NFS protocol. We recommend that you use v3. NAS Extreme file systems support NFS v3 only.
- Label: Attach 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 pods.
Use the following nas-pod.yaml file to create pods.
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