Mounting NFS for Kubernetes Servers
2024-01-22
This document will guide you through the configuration of NFS (Network File System) mounting for Kubernetes servers. This includes the necessary steps to enable Kubernetes clusters to access shared storage.
Cluster Server-Side
Copy Successful
# Install the server-side.
sudo apt install nfs-kernel-server
Copy Successful
# Start the server.
sudo systemctl start nfs-server
Copy Successful
# Mount the directory (replace <source> and <target> directory paths as needed).
# <source> is the path of the directory to be mounted.
# <target> is the target path to mount.
# Example: sudo mount --bind /mnt/disks/data /
sudo mount --bind <source> <target>
Copy Successful
# Open /etc/fstab
sudo vim /etc/fstab
Copy Successful
# Write for automatic mounting on reboot and save/close the file.
# <source> is the path of the directory to be mounted.
# <target> is the target path to mount.
# Example: /mnt/disks/data / none bind 0 0
<target> <source> none bind 0 0
Copy Successful
# Open /etc/exports
sudo vim /etc/exports
Copy Successful
# Set permissions for cluster access to NFS.
# <source> is the path of the directory to be mounted.
# <ip> is the host IP to access NFS, which is the internal IP of the cluster.
# Example: /mnt/disks/data 10.10.10.1/24(rw,fsid=0,no_root_squash,no_subtree_check,sync,no_wdelay)
<source> <ip>/24(rw,fsid=0,no_root_squash,no_subtree_check,sync,no_wdelay)
Copy Successful
# Set permissions for node access to NFS, then save/close the file.
# <source> is the path of the directory to be mounted.
# <ip> is the host IP to access NFS, which is the internal IP of the node.
# Example: /mnt/disks/data 10.10.10.2/24(rw,no_root_squash,no_subtree_check,sync,no_wdelay)
<source> <ip>/24(rw,no_root_squash,no_subtree_check,sync,no_wdelay)
Copy Successful
# Reload /etc/exports configuration.
sudo exportfs -ar
Node Client-Side
Copy Successful
# Install the client-side.
sudo apt install nfs-common
Copy Successful
# Create the mounting directory.
# <source> is the path of the directory to be mounted.
# Example: sudo mkdir -p /mnt/disks/data
sudo mkdir -p <source>
Copy Successful
# Mount the NFS disk.
# <ip> is the host IP to access NFS, which is the internal IP of the cluster.
# <target> is the target path to mount.
# <source> is the path of the directory to be mounted.
# Example: sudo mount -t nfs 10.10.10.1:/ /mnt/disks/data
sudo mount -t nfs <ip>:<target> <source>
Copy Successful
# Open /etc/fstab
sudo vim /etc/fstab
Copy Successful
# Write for automatic mounting on reboot and save/close the file.
# <ip> is the host IP to access NFS, which is the internal IP of the cluster.
# <target> is the target path to mount.
# <source> is the path of the directory to be mounted.
# Example: 10.10.10.1:/ /mnt/disks/data nfs defaults,nofail,_netdev 0 0
<ip>:<target> <source> nfs defaults,nofail,_netdev 0 0
Other
You can also mount a single disk into the cluster server and then share it with node clients using NFS. This allows you to implement a data backup plan for this individual disk.
For GCP disk mounting, please refer to GCP Documentation.