This topic describes how to create a subdirectory in a NAS file system and map it to a dynamically provisioned persistent volume (PV) for an application.
Prerequisites
A Kubernetes cluster has been created and the FlexVolume plugin is installed. For more information, see Create a managed Kubernetes cluster.
The alicloud-nas-controller component has been deployed. For more information, see Install and upgrade the FlexVolume component.
Precautions
If the securityContext.fsgroup parameter is configured in an application template, kubelet executes the chmod or chown operation after the volume is mounted. This can cause the mount process to take a long time.
If you have configured the securityContext.fsgroup parameter and need to reduce the mount time, see Extended mount time for NAS volumes.
Create a dynamic NAS volume
Configure a StorageClass.
The following is an example:
apiVersion: storage.k8s.io/v1 kind: StorageClass metadata: name: alicloud-nas mountOptions: - nolock,tcp,noresvport - vers=3 parameters: server: "23a9649583-i****.cn-shenzhen.nas.aliyuncs.com:/nasroot1/" driver: flexvolume provisioner: alicloud/nas reclaimPolicy: DeleteParameter
Description
mountOptions
The mount options for the generated PV. These options are used when the NAS volume is mounted.
server
The list of NAS mount targets used to provision the PV. The format is nfsurl1:/path1,nfsurl2:/path2. When multiple servers are specified, the PV provisioned by this StorageClass uses the servers in a round-robin manner. For Extreme NAS file systems, the path must start with /share.
driver
FlexVolume and NFS drivers are supported. The default is NFS.
reclaimPolicy
The reclaim policy of the PV. Set this to Retain.
If you set this policy to Delete, the corresponding subdirectory in the NAS file system is renamed by default after the PV is deleted. For example, path-name is renamed to archived-path-name.
To delete the corresponding storage directory from the file system, set
archiveOnDeleteto false in the StorageClass.
Use a dynamically provisioned NAS volume in a StatefulSet.
The following example shows how to create a service and a StatefulSet:
apiVersion: v1 kind: Service metadata: name: nginx labels: app: nginx spec: ports: - port: 80 name: web clusterIP: None selector: app: nginx --- apiVersion: apps/v1 kind: StatefulSet metadata: name: web spec: selector: matchLabels: app: nginx serviceName: "nginx" replicas: 5 volumeClaimTemplates: - metadata: name: html spec: accessModes: - ReadWriteOnce storageClassName: alicloud-nas resources: requests: storage: 2Gi template: metadata: labels: app: nginx spec: containers: - name: nginx image: nginx:alpine volumeMounts: - mountPath: "/data" name: html