All Products
Search
Document Center

File Storage NAS:Mount a NAS file system by using a volume

Last Updated:Nov 01, 2024

This topic describes how to use a built-in Kubernetes volume to mount a File Storage NAS (NAS) file system on a Kubernetes cluster.

Prerequisites

  • A Network File System (NFS) file system is created. For more information, see Create a file system.

    To encrypt data in a NAS file system, you must configure the encryption type when you create the NAS file system.

  • A mount target is created. For more information, see Manage mount targets.

  • A self-managed Kubernetes cluster is created and the cluster version is 1.16 or later.

  • Port 111 and port 2049 are specified in the security group rule of the pod scheduling node. For more information, see Add a security group rule.

  • If the self-managed Kubernetes cluster is deployed in a data center, the data center must be connected to Alibaba Cloud. You can connect the data center to Alibaba Cloud by using Express Connect, Smart Access Gateway (SAG), or VPN Gateway. For more information, see the following topics:

Limits

The limits on mounting scenarios, the number of file systems, and file sharing protocols vary with the storage class of NAS file systems. For more information, see Limits.

Important

Before you unmount a NAS file system, do not delete the mount target of the file system. Otherwise, an operating system hang may occur.

Procedure

  1. Log on to the self-managed Kubernetes cluster.

  2. Configure the nodes in the Kubernetes cluster.

    Note

    You must configure all nodes in the Kubernetes cluster. Before you add a node to the Kubernetes cluster, you must perform the following steps.

    1. Install an NFS client. For more information, see Step 1: Install an NFS client.

    2. Run the following command to configure the /etc/nfsmount.conf file:

      cat <<EOF >> /etc/nfsmount.conf
      [ Server "file-system-id.region.nas.aliyuncs.com" ]
      vers=3
      Proto=tcp
      Lock=False
      resvport=False
      rsize=1048576
      wsize=1048576
      hard=True
      timeo=600
      retrans=2
      EOF

      In the preceding command, file-system-id.region.nas.aliyuncs.com is the domain name of the mount target for the NAS file system. Replace the domain name with the actual value. To obtain the domain name of the mount target, perform the following steps: Log on to the NAS console. On the File System List page, click the ID of the file system. On the details page, click the Mount Targets tab. Then, move the pointer over the 挂载点 icon in the Mount Target column.

      Note
      • We recommend that you use the NFSv3 protocol to mount a NAS file system.

      • All the parameters in the preceding command are required. You do not need to modify other parameters except the file-system-id.region.nas.aliyuncs.com and vers parameters. The vers parameter specifies the protocol version.

    3. Verify that the NAS file system is connected to the Kubernetes cluster.

      1. Run the following command to mount the NFS file system:

        mount -t nfs file-system-id.region.nas.aliyuncs.com:/ /mnt 

        In the preceding command, file-system-id.region.nas.aliyuncs.com is the domain name of the mount target for the NAS file system. Replace the domain name with the actual value.

        If the mount fails, ping the domain name of the mount target and check whether port 2049 is connected. If the mount failure is not caused by network issues, use the script tool to troubleshoot the issue. For more information, see Run the auto-check script to troubleshoot the failure of mounting an NFS file system on Linux.

      2. Run the following command to view the mount information:

        mount | grep nfs | grep mnt 

        If the parameters include vers=3, hard, noresvport, and nolock, the network is connected.参数信息

        After you confirm that the network is connected, run the umount /mnt command to delete the mounted NFS file system.

  3. Start a pod to mount the NFS file system by using a built-in Kubernetes volume.

    In this example, a pod named nginx is started to mount the NFS file system.

    1. Configure the nginx.yaml file.

      cat  << EOF > ./nginx.yaml
      apiVersion: apps/v1
      kind: Deployment
      metadata:
        name: nginx-deployment
      spec:
        selector:
          matchLabels:
            app: nginx
        replicas: 1
        template:
          metadata:
            labels:
              app: nginx
          spec:
            containers:
            - name: nginx
              image: nginx:1.14.2
              ports:
              - containerPort: 80
              volumeMounts:
              - mountPath: /data
                name: test-nfs
            volumes:
            - name: test-nfs
              nfs:
                server: file-system-id.region.nas.aliyuncs.com    # The domain name of the mount target for the NAS file system. Replace the domain name with the actual value. Example: 7bexxxxxx-xxxx.ap-southeast-1.nas.aliyuncs.com. 
                path: /    # The directory path of the NAS file system. The directory must be an existing directory or the root directory. The root directory of a General-purpose NAS file system is "/". The root directory of an Extreme NAS file system is "/share". 
      EOF
    2. Enable the nginx pod to use the NFS file system.

      kubectl apply -f ./nginx.yaml
  4. Check whether the pod is started as expected and whether the NFS file system is mounted.

    1. Run the following command to check the status of the pod.

      • Command

        kubectl get pods | grep nginx 
      • Output

        If the pod is in the Running state, the pod is started as expected.

        image

    2. Run the following command to view the mount result.

      • Command

        kubectl exec nginx-deployment-9b9b684f5-mgrkh  -- df -h /data
      • Output

        If an output similar to the following example appears, the mount is successful.

        image