This topic creates a sub-directory in a NAS file system and uses this sub-directory to create a dynamic PV.

Prerequisites

The flexvolume driver is already installed in the cluster.

You have installed alicloud-nas-controller. For more information, see Install the plug-in.

Create a dynamic PV

  1. Create a StorageClass.
    A sample configuration is provided as follows:
    apiVersion: storage.k8s.io/v1
    kind: StorageClass
    metadata:
      name: alicloud-nas
    mountOptions:
    - nolock,tcp,noresvport
    - vers=3
    parameters:
      server: "23a9649583-iaq37.cn-shenzhen.nas.aliyuncs.com:/nasroot1/"
      driver: flexvolume
    provisioner: alicloud/nas
    reclaimPolicy: Delete
    Note
    • MountOptions: The mount parameter of the PV.
    • server: The mount point of the NAS volume. The format is as follows: nfsurl1:/path1,nfsurl2:/path2. When multiple servers are configured, the PV created through this StorageClass will use the above servers in round-robin manner. For NAS extreme, the path must start with /share.
    • driver: Supports flexvolume and NFS. Default is NFS.
    • reclaimPolicy: The reclaim policy of the PV. We recommend that you use Retain.
      • If you set the parameter to Delete, the NAS directory corresponding to the PV will be automatically renamed when you delete the PV. For example, path-name will be changed to archived-path-name.
      • If you need to delete the NAS directory corresponding to the PV, set archiveOnDelete to false in StorageClass configuration.
  2. Use the dynamic PV.
    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:
      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