Kubernetes – Persistent NFS Storage On Control Plane For Minimal Cluster

Kubernetes logo

Got a minimal (k3s) cluster running? Need persistent storage, NOT dependent on the pods worker node? For testing and small scale deployments, an NFS-server can be installed on any of the control nodes and mounted on the worker nodes. Here’s how:

First, install and configure nfs-server on control node

# Install
~$ sudo apt update && sudo apt install -y nfs-kernel-server

# Share local storage
~$ sudo vi /etc/exports
...
/var/nfs/ *(rw,sync,no_subtree_check,no_root_squash,anonuid=65534,anongid=65534)

# Load NFS configuration
~$ sudo exportfs -a

Second, install nfs-client on all the worker nodes

~$ sudo apt update && sudo apt install -y nfs-common

Third, configure the NFS-Provisioner (nfs-subdir-external-provisioner)

# Add helm repo
~$ sudo helm repo add nfs-subdir-external-provisioner https://kubernetes-sigs.github.io/nfs-subdir-external-provisioner/

# Install the provisioner
~$ sudo env KUBECONFIG=/path/to/kubeconfig.yaml \
helm install nfs-subdir-external-provisioner nfs-subdir-external-provisioner/nfs-subdir-external-provisioner \
  --set nfs.server=KubernetesControlNodeWithNFS \
  --set nfs.path=/var/nfs

You can now map a persistent storage claim, example:

apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: example-pv-claim
  labels:
    app: example
spec:
  storageClassName: nfs-client
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: 2Gi

Shared storage is the best storage 👾

Leave a Reply

Your email address will not be published. Required fields are marked *