Certainly! Below is a step-by-step guide to set up NFS and use it with Kubernetes using the nfs-subdir-external-provisioner, split into Master Node and Worker Node steps. I'll clarify what runs on the NFS server, master node, and worker nodes.
Assumptions
- You have a Linux VM (let's say with IP
192.168.10.15) which will be your NFS Server (can be either master or separate node).
- Your Kubernetes cluster consists of a Master Node and one or more Worker Nodes.
192.168.10.0/24 subnet is your network.
Part 1: Setup NFS Server (Can be master or separate VM)
This is where you install and configure NFS server which will share /srv/k8s directory.
1. Install NFS Server
sudo apt update
sudo apt install -y nfs-kernel-server tree
2. Create NFS export directories
sudo mkdir -p /srv/k8s/volume
sudo mkdir -p /srv/k8s/backup
3. Set permission for NFS share
sudo chown -R nobody:nogroup /srv/k8s/
sudo chmod -R 777 /srv/k8s/
- Explanation: Using
nobody:nogroup means the NFS share has permissions for any user.
4. Configure NFS exports
Edit the /etc/exports file:
sudo nano /etc/exports
Add the following line (replace 192.168.10.0/24 with your actual client subnet):
/srv/k8s/ 192.168.10.0/24(rw,no_root_squash,sync,no_subtree_check)
rw = read/write access
no_root_squash = allows root privileges from clients (needed for some Kubernetes scenarios)
sync for safer writes
no_subtree_check for efficiency
5. Export NFS shares and start server
sudo exportfs -rav
sudo systemctl restart nfs-kernel-server
sudo systemctl enable nfs-kernel-server
6. Verify exports
sudo exportfs -v
Part 2: Mount NFS manually on Master Node (for testing)
(You can skip this if you want only Kubernetes to manage mounting)
sudo mount -t nfs 192.168.10.15:/srv/k8s/ /mnt
ls /mnt
sudo umount /mnt
If you see shared files under /mnt, your NFS server is working correctly.
Part 3: Kubernetes Setup Using Helm for Dynamic Provisioning
You will install an external provisioner that allows dynamic provisioning on top of NFS volumes.
Step 1: Install Helm (On master or wherever you manage the cluster)
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash
Step 2: Add NFS subdir external provisioner repository
helm repo add nfs-subdir-external-provisioner https://kubernetes-sigs.github.io/nfs-subdir-external-provisioner/
helm repo update
Step 3: Deploy the NFS external provisioner
Make sure your Kubernetes cluster really can reach the NFS server IP 192.168.10.15. This will usually run on worker nodes because it provisions the volumes.
kubectl create namespace nfs
helm install nfs-subdir-external-provisioner nfs-subdir-external-provisioner/nfs-subdir-external-provisioner \
--namespace nfs \
--set nfs.server=192.168.10.15 \
--set nfs.path=/srv/k8s/volume
--set nfs.server=192.168.10.15 — IP where NFS server is reachable.
--set nfs.path=/srv/k8s/volume — path on NFS server to use for volumes.
Step 4: Verify StorageClass is created
kubectl get sc
You should see a new StorageClass named something like nfs-client. This StorageClass will dynamically provision volumes using your NFS server.
Part 4: Use NFS StorageClass for MySQL Deployment
Now you can install MySQL helm chart using NFS storage.
helm repo add bitnami https://charts.bitnami.com/bitnami
helm repo update
helm install mysql-nfs bitnami/mysql --version 12.3.5 \
--set primary.persistence.storageClass=nfs-client
This tells MySQL to use your NFS provisioning StorageClass to create persistent volumes dynamically.
Summary of Where to Execute Commands
| Step | Node | Notes |
|---|
| Install NFS server | NFS server (can be master or separate) | IP 192.168.10.15 |
| Create export dirs | NFS server | |
Configure /etc/exports | NFS server | |
Start and enable nfs-kernel-server | NFS server | |
| Test mount NFS manually | Master node (just test) | Optional for validation |
| Install Helm | Master node | Usually you manage cluster from master |
Add nfs-subdir-external-provisioner repo | Master node | |
Deploy nfs-subdir-external-provisioner Helm chart | Master node (operator schedules pods to worker nodes) | Provisioner runs as pod on worker nodes |
| Install MySQL chart | Master node | Uses the NFS storage class |
Additional Notes:
- Ensure network connectivity & firewall allows NFS (port 2049 TCP/UDP) between nodes.
- Make sure NFS server's IP (
192.168.10.15) is reachable by all worker nodes.
- Use
kubectl get pods -n nfs to check the provisioner pods are running correctly.
- You might want to label nodes or change StorageClass parameters for production scenarios.
If you want a full end-to-end script, or if you want help troubleshooting any step, feel free to ask!