Persistent Data (PV) with NFS in an On-Premises Kubernetes Environment

Bumgu

2024/04/28

Categories: DevOps SRE Tags: Kubernetes

Master Server

1. Install the NFS server on the master server

2. Specify the shared directory

Then restart NFS: systemctl restart nfs-server

NFS options:

ro: Grants read-only access.  
  
rw: Grants read and write access.  
  
root_squash: Maps the client root account to the nobody account on the server.  
  
no_root_squash: Allows the root account on both the client and server.  
  
sync: Writes filesystem changes synchronously.  
  
all_squash: Maps all client users, not only root, to the anonymous account.

Client (worker node) server

1. Install the NFS client

2. Mount

3. Verify that it is mounted

Create a test.txt file on 192.168.64.129. If we check the shared NFS directory on server 131, the NFS server: we can see that it has been shared.

Master node

1. Install StorageClass

StorageClass is a provisioning method that dynamically creates volumes in a cloud environment to meet the requirements of a PV. In other words, when a PV specifies volume size, whether it should be an SSD, filesystem type, zone, and so on, it creates a matching volume.

Install it using helm.

# Add the StorageClass repository
helm repo add nfs-subdir-external-provisioner https://kubernetes-sigs.github.io/nfs-subdir-external-provisioner/

# Verify the StorageClass repository
helm repo list
# Install the StorageClass provisioner
helm install nfs-subdir-external-provisioner nfs-subdir-external-provisioner/nfs-subdir-external-provisioner \
 --set nfs.server=${NFS_SERVER_IP} \
 --set nfs.path=${NFS_SERVER_SHARED_DIRECTORY} \
 --set storageClass.name=nfs \
 --set storageClass.defaultClass=true
# Verify the installation
kubectl get sc

2. Use storageClass

Now specify StorageClassName in the existing PVC. When you check StorageClass with kubectl get sc, its name is nfs, so enter nfs for StorageClassName. After installing with helm, a data folder appears in the shared directory.

References:
https://junwork123.tistory.com/33
https://www.digitalocean.com/community/tutorials/how-to-set-up-an-nfs-mount-on-ubuntu-20-04

>> Home