How to use NFS in Kubernetes Cluster — Storage Class

Fabio Fernandes
Level Up Coding
Published in
7 min readJan 4, 2021

--

Attention: The docker image used in this article: quay.io/external_storage/nfs-client-provisioner has not worked since Kubernetes 1.20. Kubernetes deprecated a field used by this provisioner. The alternative is to replace it by the image: registry.k8s.io/sig-storage/nfs-subdir-external-provisioner:v4.0.2.

In the previous article, we talked about connecting to an NFS Server, only via Persistent Volumes configuration.

In conjunction with the direct node mapping to NFS Method we saw in this article, this method is the most used way to use NFS Server with Kubernetes.

In this third and last article of the series, I’ll show you how to automate part of the work, creating a persistent volume.

It saves a lot of work in the long run but requires more work with the initial configuration.

Most of the tutorials you will see on the internet to create custom storage classes uses scripts or helm package installations. To continue with this series's pattern, I will show you how to do it using only yml config files. It will make things a bit more laborious, but I believe you will learn a lot more than just run a command.

General Notes

Article Series

This article is part of a series about Kubernetes using NFS Server as a source for persistent volumes. Here is the list of articles of this series:

  1. Configuring the NFS Server
  2. Method 1 — Mapping NFS drive to a local folder into each node
  3. Method 2 — Connecting directly to the NFS server via persistent volume configuration
  4. Creating a storage class to create a persistent volume via claims automatically. (this one)

Source Code

All the files used in this article are published in this GitHub repository: https://github.com/fabiofernandesx/k8s-volumes. Feel free to clone it or even open a pull request if you find something that needs to be fixed or added.

Home Lab

For this article series, I’ll use my raspberry pi Kubernetes cluster, but the commands should work in any environment, including cloud or virtual machines. If you are interested in seeing how to create a raspberry pi k8s cluster, you can find it here: Yet Another Raspberry Pi k8’s Cluster, or if you interested in…

--

--

I’ve been helping companies to transform their big ideas in profitable business for more than 20 years