Use a Kubernetes in-tree NFS volume to mount a NAS file system on a self-managed Kubernetes cluster.
Prerequisites
Before you begin, make sure that you have:
A NAS file system with the NFS protocol enabled. To encrypt data, configure the encryption type when you create the file system. For more information, see Create a file system.
A mount target for the NAS file system. For more information, see Manage mount targets.
A self-managed Kubernetes cluster that runs Kubernetes 1.16 or later.
Ports 111 and 2049 open in the security group of the worker nodes. For more information, see Add a security group rule.
A network connection to Alibaba Cloud through Express Connect, Smart Access Gateway (SAG), or VPN Gateway if the cluster is in an on-premises data center.
Limits
The limits on mounting scenarios, the number of file systems, and file sharing protocols vary based on the storage type of NAS file systems. For more information, see Limits.
Do not delete the mount target of a NAS file system before you unmount it. Deleting a mount target while the file system is still mounted may cause the operating system to become unresponsive.
Procedure
Step 1: Install and configure the NFS client
Perform the following steps on every node in the cluster. Complete these steps before you add a new node.
Install the NFS client. For more information, see Step 1: Install the NFS client.
Run the following command to configure the
/etc/nfsmount.conffile: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 EOFReplace
file-system-id.region.nas.aliyuncs.comwith the DNS name of your mount target. To find the DNS name:Log on to the NAS console.
On the File System List page, click the file system ID.
Click the Mount Targets tab and hover over the copy icon in the Mount Target column.
The following table describes the key parameters:
Parameter
Description
versThe NFS protocol version. We recommend NFSv3.
rsize/wsizeThe read and write buffer sizes, in bytes. Default:
1048576(1 MiB).hardEnables hard mounts. The client retries NFS requests indefinitely until the server responds.
timeoThe timeout for NFS requests, in tenths of a second. Default:
600(60 seconds).retransThe number of retries before the client reports an error. Default:
2.NoteAll parameters are required. Only modify the mount target DNS name and the
versvalue. Keep all other parameters unchanged.
Step 2: Verify the network connection
Run the following command to mount the NAS file system to a temporary directory:
mount -t nfs file-system-id.region.nas.aliyuncs.com:/ /mntReplace
file-system-id.region.nas.aliyuncs.comwith the DNS name of your mount target.NoteIf the mount fails, ping the mount target DNS name and verify that port 2049 is reachable. If the failure is not caused by network issues, use the troubleshooting script. For more information, see Automatic check script for failures to mount an NFS file system on a Linux server.
Run the following command to verify the mount parameters:
mount | grep nfs | grep mntIf the output contains
vers=3,hard,noresvport, andnolock, the connection is successful.After you confirm the connection, run the following command to unmount the temporary mount:
umount /mnt
Step 3: Deploy a pod with a NAS volume
The following example creates an nginx Deployment that mounts a NAS file system.
Create a file named
nginx.yamlwith the following content: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 # Replace with the DNS name of your mount target. Example: 7bexxxxxx-xxxx.ap-southeast-1.nas.aliyuncs.com. path: / # Use "/" for General-purpose NAS or "/share" for Extreme NAS.Run the following command to deploy the pod:
kubectl apply -f ./nginx.yaml
Step 4: Verify the mount
Run the following command to check the pod status:
kubectl get pods | grep nginxExpected output:
If the pod is in the
Runningstate, the pod started successfully.Run the following command to verify that the NAS file system is mounted:
kubectl exec nginx-deployment-9b9b684f5-xxxxx -- df -h /dataReplace
nginx-deployment-9b9b684f5-xxxxxwith the actual pod name from the previous step.If the output shows the NAS file system mounted at
/data, the mount is successful.