Today we will talk about option to add any NFS storage to your existing Kubernetes cluster. We will need some minimum requirements like Kubernetes version newer than 1.18 and a running server to act as NFS server. We will not talk today about configuring NFS in HA mode. As Linux distro we will use today Ubuntu but can be used others.
Steps to add NFS storage in Kubernetes:
- Create the NFS server and export directory
- Define a PersistentVolume (PV) with NFS settings
- Create a PersistentVolumeClaim (PVC)
- Mount the PVC in your pod definition
- Test read/write access from containers
Install and configure NFS server
Installing a fresh NFS server can be accomplished with the following commands:
# apt install -y nfs-server
# mkdir /nfs
# cat << EOF >> /etc/exports
/nfs <kubernetes_worker_ip>(rw,no_subtree_check,no_root_squash) #repeat this line for every worker ip
EOF
# systemctl enable --now nfs-server
# exportfs -ar
Prepare Kubernetes workers for NFS storage
We will need to install NFS Client on each Kubernetes worker in order to be able to access NFS Server. This can be don using commend:
# apt install -y nfs-common
Configure Kubernetes for dynamic provisioning
We will need to install NFS provisioner (nfs-subdir-external-provisioner) to be able to provision PV using SC.
$ helm repo add nfs-subdir-external-provisioner https://kubernetes-sigs.github.io/nfs-subdir-external-provisioner
$ helm install nfs-subdir-external-provisioner nfs-subdir-external-provisioner/nfs-subdir-external-provisioner \
--create-namespace \
--namespace nfs-provisioner \
--set nfs.server=<nfs_server_ip> \
--set nfs.path=/nfs
Configure NFS Storage as default storage
$ kubectl patch storageclass nfs-client -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
Need help managing Kubernetes clusters or designing hybrid storage setups?
→ Explore our Virtualization & Container Services
0 Comments