Mount NAS on a self-managed Kubernetes cluster using an in-tree NFS volume.
Prerequisites
Before you begin, make sure the following requirements are met:
-
An NFS-protocol NAS file system is created. To encrypt data, enable encryption during file system creation. For more information, see Create a file system.
-
A mount target is added to the file system. For more information, see Manage mount targets.
-
A self-managed Kubernetes cluster running version 1.16 or later.
-
Ports 111 and 2049 are open in the security group of the worker nodes. For more information, see Add a security group rule.
-
A network connection to Alibaba Cloud is established through Express Connect, Smart Access Gateway (SAG), or VPN Gateway if the cluster is in an on-premises data center.
Limits
Limits on mounting scenarios, file system count, and file sharing protocols vary by NAS storage type. For more information, see Limits.
Do not delete a mount target before unmounting the file system. The operating system may become unresponsive.
Procedure
Step 1: Install and configure the NFS client
Repeat these steps on every cluster node, including nodes added later.
-
Install the NFS client. For more information, see Step 1: Install the NFS client.
-
Configure
/etc/nfsmount.conf: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.
Key parameters:
Parameter
Description
versNFS protocol version. Recommended: NFSv3.
rsize/wsizeRead and write buffer sizes in bytes. Default:
1048576(1 MiB).hardHard mount mode. The client retries indefinitely until the server responds.
timeoNFS request timeout in tenths of a second. Default:
600(60 seconds).retransRetries before the client reports an error. Default:
2.NoteAll parameters are required. Only change the mount target DNS name and the
versvalue. -
Step 2: Verify the network connection
-
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 check that port 2049 is reachable. For non-network failures, run the troubleshooting script. For more information, see Automatic check script for NFS mount failures.
-
Verify the mount parameters:
mount | grep nfs | grep mntOutput containing
vers=3,hard,noresvport, andnolockconfirms a successful connection. -
Unmount the temporary mount:
umount /mnt
Step 3: Deploy a pod with a NAS volume
The following example creates an nginx Deployment with a NAS volume mount.
-
Create
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 # 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. -
Deploy the pod:
kubectl apply -f ./nginx.yaml
Step 4: Verify the mount
-
Check the pod status:
kubectl get pods | grep nginxExpected output:
A
Runningstate confirms the pod started successfully. -
Verify the NAS file system is mounted:
kubectl exec nginx-deployment-9b9b684f5-xxxxx -- df -h /dataReplace
nginx-deployment-9b9b684f5-xxxxxwith the actual pod name.Output showing the file system mounted at
/dataconfirms success.