All Products
Search
Document Center

:Mount a statically provisioned NAS volume

Last Updated:Nov 15, 2024

Apsara File Storage NAS (NAS) is a distributed file system that supports shared access, elastic scaling, high reliability, and high performance. This topic describes how to mount a statically provisioned NAS volume, and how to enable persistent storage and shared storage by using a statically provisioned NAS volume.

Prerequisites

  • An Alibaba Cloud Container Compute Service (ACS) cluster is created. For more information, see Create an ACS cluster.

  • NAS is activated and a NAS file system is created. For more information, see Create a NAS file system.

    Note

    If you want to encrypt data in a NAS volume, configure the encryption settings when you create the NAS file system.

  • A mount target is created for the NAS file system. For more information, see Manage mount targets.

    Note

    The mount target and the cluster node to which you want to mount the NAS file system must belong to the same virtual private cloud (VPC).

Use scenarios

  • NAS volumes are suitable for applications that require high disk I/O throughput.

  • NAS volumes can be used to persist data. The read and write performance of NAS is hither than Object Storage Service (OSS).

  • NAS volumes can be used to share files among hosts.

Precautions

  • If a NAS file system is mounted to multiple pods, the data in the file system is shared by the pods. In this case, the application must be able to synchronize data across the pods if the data in the NAS file system is modified by multiple pods.

    Note

    You cannot grant permissions to access the / directory (root directory) of the NAS file system. The user account and user group to which the directory belongs cannot be modified.

  • You cannot specify the securityContext.fsgroup parameter in the application YAML template. This may cause mount failures.

  • You can mount a dynamically provisioned NAS volume in filesystem mode to share the root directory (/) of the NAS file system.

  • You cannot use the Container Storage Interface (CSI) plug-in to mount Server Message Block (SMB) file systems.

  • We recommend that you use the NFSv3 file sharing protocol.

  • You can mount a NAS volume only to ECS instances in the same virtual private cloud (VPC) as the NAS file system.

  • General-purpose and Extreme NAS file systems have different limits such as the limits on mounting connectivity, the number of file systems, and file sharing protocols. For more information, see Limits.

  • Before you use NAS volumes, we recommend that you update the CSI plug-in to the latest version.

  • After a mount target is created, wait until the mount target changes to the Available state.

  • Do not delete the mount target of a NAS file system before you unmount the NAS file system. Otherwise, an operating system hang issue may occur.

Create a statically provisioned NAS volume

Use the console

Step 1: View the region and zone of the ACS cluster

  1. Log on to the ACS console. In the left-side navigation pane, click Clusters.

  2. On the Clusters page, select your ACS cluster.

  3. In the left-side navigation pane of the cluster management page, click Cluster Information.

  4. On the Cluster Information page, click the Cluster Resources tab.

  5. Find the virtual private cloud (VPC) and pod vSwitch of the ACS cluster and click them to view details. Record the IDs and names of the VPC and pod vSwitch and the region and zone information.

image.png

Step 2: Create a NAS file system and mount target

  1. Log on to the NAS console.

  2. Click Create General-purpose NAS File System in the lower part of the page.

  3. On the General-purpose NAS (Pay-as-you-go) page, configure parameters.

    1. Region: Select the region of the ACS cluster.

    2. Zone: Select the zone of the ACS cluster in Step 1.

    3. Select a storage class.

    4. Protocol Type: Select NFS.

    5. VPC: Select the VPC of the ACS cluster. This parameter requires you to select the name instead of the ID of a VPC.

    6. vSwitch: Select a vSwitch in the preceding zone. This parameter requires you to select the name instead of the ID of a vSwitch.

  4. After the NAS file system is created, choose File System > File System List in the left-side navigation pane. Then, click the NAS file system that you created to view details.

  5. In the left-side navigation pane of the file system details page, click Mount Targets. Then, click Add Mount Target to add a mount target and wait until the mount target enters the Available state.

image.png

Note

To create an Extreme NAS file system, you need to first create the file system and log on to the file system to add a mount target. Configure the parameters of the Extreme NAS file system, such as the VPC and vSwitch, as described in the preceding step.

Step 3: Create a PVC

  1. Log on to the ACS console. In the left-side navigation pane, click Clusters.

  2. On the Clusters page, select your ACS cluster.

  3. In the left-side navigation pane of the cluster management page, choose Volumes > Persistent Volume Claims.

  4. In the upper-right corner of the Persistent Volume Claims page, click Create.

  5. In the Create PVC dialog box, set the following parameters.

    Parameter

    Description

    PVC Type

    Valid values: Cloud Disk and NAS. In this example, NAS is selected.

    Name

    The name of the PVC. The name must be unique within the cluster.

    Allocation Mode

    Select Use Mount Target Domain Name.

    Capacity

    The capacity of the PV.

    Note

    The capacity claimed by the PVC cannot exceed the capacity of the PV that is bound to the PVC.

    Mount Target Domain Name

    Enter the mount target you obtained in Step 2. By default, the root directory (/) of the NAS file system is shared.

    Important
    • To share a subpath or you created an Extreme NAS file system in Step 2, you must use kubectl to set the mount target.

    • The shared directory of an Extreme NAS file system must start with /share, for example, /share and /share/subdir.

  6. Click Create.

    After the PVC is created, you can find the PVC in the list. The PVC is in the Pending state, which means that the PVC is not used by any pod.

image

Step 4: Create an application

  1. In the left-side navigation pane of the cluster details page, choose Workloads > Deployments.

  2. On the Deployments tab, click Create from Image.

  3. Configure the Deployment parameters.

    The following section describes how to configure the volume parameters. For more information about other parameters, see Create a stateless application by using a Deployment.

    You can create volumes that use local storage or cloud storage in ACS clusters.

    • Add Local Storage: You can select ConfigMap, Secret, or EmptyDir to mount the mount source to a path in containers. For more information, see Volumes.

    • Add PVC: You can select cloud storage.

    In this example, a NAS volume is mounted to the /tmp path in a container.

    image.png

  4. Set other parameters and click Create.

    After the Deployment is created, you can mount the volume to the pods created by the Deployment.

Use kubectl

Prerequisite: A kubectl client is connected to the ACS cluster. For more information, see Obtain the kubeconfig file of a cluster and use kubectl to connect to the cluster.

Step 1: Create a PVC used for static provisioning.

  1. Create a file named pvc-nas.yaml and copy the following content to the file:

    kind: PersistentVolumeClaim
    apiVersion: v1
    metadata:
      name: pvc-nas
      annotations:
        csi.alibabacloud.com/mountpoint: ****.nas.aliyuncs.com
        csi.alibabacloud.com/mount-options: nolock,tcp,noresvport
    spec:
      accessModes:
        - ReadWriteMany
      resources:
        requests:
          storage: 20Gi
      storageClassName: alibaba-cloud-nas

    Parameter

    Description

    name

    The name of the PVC.

    metadata.annotations.csi.alibabacloud.com/mountpoint

    The mount target of the NAS file system that you created.

    Important

    If you enter ****.nas.aliyuncs.com, the root directory (/) of the NAS file system is shared. If you enter ****.nas.aliyuncs.com:/dir, the /dir directory of the NAS file system is shared. If the /dir directory does not exist, the system automatically creates one.

    metadata.annotations.csi.alibabacloud.com/mount-options

    The mount parameter. By default, this parameter is not specified.

    accessModes

    The access mode of the PVC.

    storage

    The capacity claimed by the PVC. The claimed capacity cannot exceed the capacity of the PV that is bound to the PVC.

  2. Run the following command to create a PVC used for static provisioning:

    kubectl create -f pvc-nas.yaml

Step 2: Create an application named nas-static and mount the PVC to the application.

  1. The following YAML template provides an example of the nas.yaml file that is used to create the nas-static application:

    apiVersion: apps/v1
    kind: Deployment
    metadata:
      name: nas-static
      labels:
        app: nginx
    spec:
      replicas: 2
      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

    Parameter

    Description

    mountPath

    The path of the container to which the NAS volume is mounted.

    claimName

    The name of the PVC that is mounted to the application.

  2. Run the following command to create an application named nas-static and mount the created PVC to the application:

    kubectl create -f nas.yaml
  3. Run the following command to query the pods that run the application:

    kubectl get pod

    Expected output:

    NAME                          READY   STATUS    RESTARTS   AGE
    nas-static-785b747ddf-q****   1/1     Running   0          32s
    nas-static-785b747ddf-z****   1/1     Running   0          32s

Verify that the NAS file system can be used to persist data

  1. Query the pods that run the application and the files in the mounted NAS file system.

    1. Run the following command to query the pods that run the application:

      kubectl get pod 

      Expected output:

      NAME                          READY   STATUS    RESTARTS   AGE
      nas-static-785b747ddf-q****   1/1     Running   0          32s
      nas-static-785b747ddf-z****   1/1     Running   0          32s
    2. Run the following command to query files in the /data path of a pod. In this example, the pod named nas-static-785b747ddf-q**** is queried.

      kubectl exec nas-static-785b747ddf-q**** -- ls /data

      No output is returned. This indicates that no file exists in the /data path.

  2. Run the following command to create a file named nas in the /data path of the nas-static-785b747ddf-q**** pod:

    kubectl exec nas-static-785b747ddf-q**** -- touch /data/nas
  3. Run the following command to query files in the /data path of the nas-static-5b5cdb85f6-n**** pod:

    kubectl exec nas-static-785b747ddf-q**** -- ls /data

    Expected output:

    nas
  4. Run the following command to delete the pod:

    kubectl delete pod nas-static-785b747ddf-q****
  5. Open another CLI and run the following command to view how the pod is deleted and recreated:

    kubectl get pod -w -l app=nas-static
  6. Verify that the file still exists after the pod is deleted.

    1. Run the following command to query the name of the recreated pod:

      kubectl get pod

      Expected output:

      NAME                          READY   STATUS    RESTARTS   AGE
      nas-static-785b747ddf-6****   1/1     Running   0          25s
      nas-static-785b747ddf-z****   1/1     Running   0          2m
    2. Run the following command to query files in the /data path of the nas-static-785b747ddf-6**** pod:

      kubectl exec nas-static-785b747ddf-6**** -- ls /data

      Expected output:

      nas

      If the nas file still exists, this means that the NAS file system can be used to persist data.

Verify that data in the NAS file system can be shared across pods

  1. Query the pods that are created for the application and the files in the mounted NAS file system.

    1. Run the following command to query the pods that are created for the application:

      kubectl get pod 

      Expected output:

      NAME                          READY   STATUS    RESTARTS   AGE
      nas-static-785b747ddf-6****   1/1     Running   0          25s
      nas-static-785b747ddf-z****   1/1     Running   0          2m
    2. Run the following command to query files in the /data path of each pod:

      kubectl exec nas-static-785b747ddf-6**** -- ls /data
      kubectl exec nas-static-785b747ddf-z**** -- ls /data
  2. Run the following command to create a file named nas in the /data path of a pod:

     kubectl exec nas-static-785b747ddf-6**** -- touch /data/nas
  3. Run the following command to query files in the /data path of each pod:

    1. Run the following command to query files in the /data path of the nas-static-785b747ddf-6**** pod:

      kubectl exec nas-static-785b747ddf-6**** -- ls /data

      Expected output:

      nas
    2. Run the following command to query files in the /data path of the nas-static-785b747ddf-z**** pod:

      kubectl exec nas-static-785b747ddf-z**** -- ls /data

      Expected output:

      nas

      When you create a file in the /data path of one pod, you can also find the file in the /data path of the other pod. This indicates that data in the NAS file system is shared by the two pods.