Setting up NFS Storage Class in Kubernetes with a Helm Chart
If you want to share files between your apps running on Kubernetes, you can use NFS. In this blog post, I will show you how to set up an NFS client using a Helm chart. This guide is simple and uses plain language.
What Is NFS?
NFS stands for Network File System. It helps you share files over the network. With NFS, your pods can use a common space to store or read data. This is very useful when you need to share data between many parts of your system.
What Is Helm?
Helm is like an app store for Kubernetes. It makes installing apps on your cluster much easier. With Helm, you can install many things with just one command.
Setting Up the NFS Server
Before you start, you need an NFS server. This is a machine that shares a folder over the network. Make sure:
- The NFS server is running.
- The shared folder has the right permission.
- Your Kubernetes nodes can reach the NFS server.
If you do not have an NFS server yet, you can set one up on Linux or use a cloud service that provides NFS.
Install the NFS Client Provisioner with Helm
There is a popular Helm chart for the NFS client provisioner called the nfs-subdir-external-provisioner. Follow these steps:
-
Add the Helm Repository
First, you need to add the Helm repository that has the chart:
helm repo add nfs-subdir-external-provisioner \ https://kubernetes-sigs.github.io/nfs-subdir-external-provisioner/ helm repo update -
Create a Custom Values File
Create a file called
values.yamlwith your settings. A simple example might look like this:nfs: server: 192.168.1.100 # Replace with your NFS server IP path: /exported/path # Replace with the shared folder path on your NFS server storageClass: name: nfs-clientIn this file, you tell the chart where your NFS server is and which folder to use.
-
Install the Helm Chart
Now install the chart with your custom values:
helm install my-nfs-client \ nfs-subdir-external-provisioner/nfs-subdir-external-provisioner \ --values values.yamlThis command will install the NFS client provisioner in your cluster. The name
my-nfs-clientis the release name. You can choose any name you like. -
Check the Installation
After the installation, check if the storage class is created:
kubectl get storageclassYou should see a new storage class called
nfs-client.(Optional) you can set the storage class as the default:
kubectl patch storageclass nfs-client -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
Using Your New Storage
Once the chart is installed, you can create a PersistentVolumeClaim (PVC) in your apps that uses the nfs-client storage class. Here is a simple PVC example:
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: my-pvc
spec:
accessModes:
- ReadWriteMany
storageClassName: nfs-client
resources:
requests:
storage: 1Gi
Apply this with:
kubectl apply -f my-pvc.yaml
Your apps can now use the PVC to store or read data from NFS.
Final Thoughts
Using an NFS client provisioner with Helm is a simple and effective way to share files among your apps in Kubernetes. This guide kept things simple:
- We explained what NFS and Helm are.
- We showed how to set up the NFS server.
- We walked through installing the NFS client provisioner with Helm.
- We gave an example to use the new storage in your app.
With these steps, you should have a working shared storage solution for your Kubernetes apps. Enjoy building your projects with easy access to shared files!