NFS default storage in Kubernetes with CDK

Image for post
Image for post

I’ve been running Kubernetes backed by NFS persistent volumes for a long time now and one of the rough edges for me has be the creation of persistent volumes(pv) and their claims(pvc). It involves me sshing to my NFS server, creating a directory for the share, creating yaml for the pv/pvc, and then finally applying these to the cluster. This was arduous, but I passed it off as acceptable since it wasn’t too often I was deploying new workloads. This process needed some help and while Kubernetes has supported default storage classes for a while, I didn’t take the time to learn how to use it or how to setup NFS to use it. I should have and hopefully I can help you as well.

Potentially Boring Details

To get your storage requests in your workloads to automagically get space off your NFS server requires a few things. First, you have to setup your NFS server. Then you have to run a workload on Kubernetes to support the NFS provisioning. This is due to Kubernetes not having NFS support internally and may or may not change in the future. Finally you have to tell your Kubernetes cluster to use this NFS provisioner for storage requests. The list of Kubernetes default providers is here. This is all easier to do than to say, so let’s get to it.

The Doing

First off, we’re going to get a Kubernetes cluster up. The easiest way is to use conjure-up. Run:

or on MacOS:

And follow that up with:

Select your addons, cloud, and a few other things and you’re off.

A few minutes later, you’re ready to move on to deploying an NFS server. Luckily this is an easy process with juju and the nfs charm. Note the constraint in order to request a larger disk.

Now we need to relate the nfs charm to the kubernetes worker charm:

That is it. You now have setup your Kubernetes cluster to hand out persistent volumes. You can verify that things are working by checking the storage classes on the cluster:

Note the (default) indicating that this provisioner is the default one. Further, we can add a persistent volume and verify that it gets bound and allocated.

That is it. Now you no longer have to ssh to your NFS server or manually create persistent volumes. Hopefully this guide has helped you see how easy it is to use a default provisioner, especially with conjure-up, juju, and the Canonical Distribution of Kubernetes. Be sure to clap if this was useful to you to encourage me to continue to write these guides!

Written by

Game programmer turned devops…

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store