Use static NAS volumes

更新时间:
复制 MD 格式

An Apsara File Storage NAS volume is a distributed file system that provides shared access, elastic scalability, high reliability, and high performance, making it ideal for scenarios such as big data analytics, data sharing, web applications, and log storage. You can use the CSI plugin to create a PersistentVolume and a PersistentVolumeClaim from an existing Apsara File Storage NAS file system. You can then mount the volume to a workload for persistent and shared storage.

  • Static volume: You must create a PersistentVolume in advance to represent an existing storage resource, such as an Apsara File Storage NAS file system. An application then creates a PersistentVolumeClaim to request a matching PersistentVolume. This method is commonly used to manage existing storage resources. By default, the bound PersistentVolumeClaim does not support online expansion.

  • Dynamic volume: You do not need to create a PersistentVolume in advance. When an application creates a PersistentVolumeClaim, the system automatically creates a new storage volume and its corresponding PersistentVolume based on the StorageClass specified in the PersistentVolumeClaim. This mode is more flexible and supports volume expansion.

Prerequisites

  • Your existing Apsara File Storage NAS file system must meet the following requirements. Otherwise, create a file system or use dynamic NAS volumes.

    • The protocol type is NFS. You cannot mount an Apsara File Storage NAS file system that uses the SMB protocol.

    • The mount target and the cluster nodes must be in the same VPC, and the mount target's Status must be Available. If you need to add a mount target, see Manage mount targets.

      You can mount an Apsara File Storage NAS file system only to pods within the same VPC. Cross-VPC mounting is not supported. However, you can mount a file system across availability zones within that VPC.

    Note

    To encrypt data in a NAS volume, configure the encryption type when you create the Apsara File Storage NAS file system.

Usage notes

Mount a static NAS volume (kubectl)

Step 1: Create a PersistentVolume

  1. Obtain the kubeconfig file of a cluster and use kubectl to connect to the cluster.

  2. Create a file named pv-nas.yaml that contains the following content.

    apiVersion: v1
    kind: PersistentVolume
    metadata:
      name: pv-nas
      labels:
        alicloud-pvname: pv-nas
    spec:
      capacity:
        storage: 5Gi
      accessModes:
        - ReadWriteMany
      csi:
        driver: nasplugin.csi.alibabacloud.com
        volumeHandle: pv-nas   # Must be the same as the PersistentVolume name.
        volumeAttributes:
          server: "0c47****-mpk25.cn-shenzhen.nas.aliyuncs.com"  # The address of the NAS mount target. The VPC of the mount target must be the same as the VPC of the cluster.
          path: "/csi"  # The subdirectory to mount.
      mountOptions:
      - nolock,tcp,noresvport
      - vers=3

    Parameter

    Description

    name

    The name of the PersistentVolume.

    labels

    The labels of the PersistentVolume.

    storage

    The capacity of the PersistentVolume.

    Important

    This setting does not limit the actual available capacity of a NAS volume. The specifications of the Apsara File Storage NAS file system determine its capacity. See General-purpose NAS and Extreme NAS to check the available capacity.

    accessModes

    The access mode. The default value is ReadWriteMany. ReadWriteOnce and ReadOnlyMany are also supported.

    driver

    The type of the driver. Set this parameter to nasplugin.csi.alibabacloud.com to use the Alibaba Cloud NAS CSI plugin.

    volumeHandle

    A unique identifier for the PersistentVolume. This value must match the PersistentVolume name and be unique across all PersistentVolumes in the cluster.

    server

    The address of the Apsara File Storage NAS mount target. The VPC of the mount target must be the same as the VPC of the cluster.

    To find the address of the mount target, see Manage mount targets.

    path

    The subdirectory of the Apsara File Storage NAS file system to mount.

    • If you do not set this parameter, the root directory is mounted by default.

    • If the directory does not exist in the Apsara File Storage NAS file system, the system automatically creates it before mounting.

    Note

    The root directory for a General-purpose NAS file system is /. The root directory for an Extreme NAS file system is /share. When you mount a subdirectory of an Extreme NAS file system, the path must start with /share, such as /share/data.

    mountOptions

    The mount parameters for the Apsara File Storage NAS file system, including the NFS protocol version. We recommend that you use NFSv3. Extreme NAS file systems support only NFSv3. For more information about the NFS protocol, see NFS protocols.

  3. Create the PersistentVolume.

    kubectl create -f pv-nas.yaml
  4. View the PersistentVolume.

    kubectl get pv

    Expected output:

    NAME     CAPACITY   ACCESS MODES   RECLAIM POLICY   STATUS      CLAIM    STORAGECLASS     VOLUMEATTRIBUTESCLASS   REASON   AGE
    pv-nas   5Gi        RWX            Retain           Available                             <unset>                          25s

Step 2: Create a PVC

  1. Save the following YAML template as pvc-nas.yaml:

    kind: PersistentVolumeClaim
    apiVersion: v1
    metadata:
      name: pvc-nas
    spec:
      accessModes:
        - ReadWriteMany
      resources:
        requests:
          storage: 5Gi
      selector:
        matchLabels:
          alicloud-pvname: pv-nas

    Parameter

    Description

    name

    Name of the PVC.

    accessModes

    Must match the PV’s access mode. Default: ReadWriteMany. You can also set the value to ReadWriteOnce or ReadOnlyMany.

    storage

    Requested storage capacity. Cannot exceed the PV's capacity.

    Important

    The actual available capacity is determined by the NAS file system specifications, not this value. See General-purpose NAS and Extreme NAS for details.

    matchLabels

    Labels used to bind the PVC to the PV.

  2. Create the PVC:

    kubectl create -f pvc-nas.yaml
  3. View the PVC:

    kubectl get pvc

    Expected output:

    NAME       STATUS   VOLUME    CAPACITY   ACCESS MODES   STORAGECLASS   VOLUMEATTRIBUTESCLASS   AGE
    pvc-nas    Bound    pv-nas    5Gi        RWX                           <unset>                 5s

Step 3: Create an application and mount NAS

  1. Save the following YAML as nas.yaml:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: nas-test
      labels:
        app: nginx
    spec:
      replicas: 2
      selector:
        matchLabels:
          app: nginx
      template:
        metadata:
          labels:
            app: nginx
        spec:
          containers:
          - name: nginx
            image: anolis-registry.cn-zhangjiakou.cr.aliyuncs.com/openanolis/nginx:1.14.1-8.6
            ports:
            - containerPort: 80
            volumeMounts:
              - name: pvc-nas
                mountPath: "/data"
          volumes:
            - name: pvc-nas
              persistentVolumeClaim:
                claimName: pvc-nas

    Parameter

    Description

    mountPath

    Container path where the NAS volume is mounted.

    claimName

    Name of the PVC to bind.

  2. Deploy the application:

    kubectl create -f nas.yaml
  3. Check pod status:

    kubectl get pod -l app=nginx

    Expected output:

    NAME                  READY   STATUS    RESTARTS   AGE
    nas-test-****-***a    1/1     Running   0          32s
    nas-test-****-***b    1/1     Running   0          32s

Verify the shared storage and persistent storage features of NAS

The Deployment created in the preceding example provisions two pods and mounts a NAS file system to the pods. You can use the following methods to verify this:

  • Create a file in one pod and view the file from the other pod to verify shared storage.

  • Recreate the Deployment. Then, check whether data stored in the file system exists in the newly created pod to verify persistent storage.

  1. View the pod information.

    kubectl get pod | grep nas-test

    Sample result:

    nas-test-*****a   1/1     Running   0          40s
    nas-test-*****b   1/1     Running   0          40s
  2. Verify shared storage.

    1. Create a file in a pod.

      In this example, the nas-test-*****a pod is used:

      kubectl exec nas-test-*****a -- touch /data/test.txt
    2. View the file from the other pod.

      In this example, the nas-test-*****b pod is used:

      kubectl exec nas-test-*****b -- ls /data

      Expected output shows that the newly created file test.txt is shared:

      test.txt
  3. Verify persistent storage.

    1. Recreate the Deployment.

      kubectl rollout restart deploy nas-test
    2. Wait until the pods are recreated.

      kubectl get pod | grep nas-test

      Sample result:

      nas-test-*****c   1/1     Running   0          67s
      nas-test-*****d   1/1     Running   0          49s
    3. Log on to a recreated pod and check whether the file still exists in the file system.

      In this example, the nas-test-*****c pod is used:

      kubectl exec nas-test-*****c -- ls /data

      The following output shows that the file still exists in the NAS file system and can be accessed from the mount directory in the recreated pod.

      test.txt

FAQ

If you encounter issues when mounting or using NAS volumes, see the following troubleshooting topics.