This storage provider allows you to use an NFS server like a native K8s storage provider, letting you to use mass storage for things like media or other large files. Why would this be useful? Things that you don't want to be replicated, for example, media (replicating 4.5TB can get expensive quick) or large data such as game servers! Of course, this does add a singe point of failure, but a lot less expensive than replicating data out to many nodes.
This recpie assumes you have an NFS server ready to go with a username and a password. Setting this up is outside the current scope of this recipe. This provider is also not to be used for persisting SQLite databases, as storing them on NFS will cause the database to corrupt.
HelmRepository
We're going to install a helm chart from the NFS Subdirectory External Provisioner chart repository, so I create the following in my flux repo:
Note that I have shortened the name to nfs-subdir, a theme you will find running throughout.1
Namespace
We need a namespace to deploy our HelmRelease and associated ConfigMaps into. Per the flux design, I create this example yaml in my flux repo at /bootstrap/namespaces/namespace-nfs-subdir.yaml:
Now that the "global" elements of this deployment have been defined, we do some "flux-ception", and go one layer deeper, adding another Kustomization, telling flux to deploy any YAMLs found in the repo at /nfs-subdir. I create this example Kustomization in my flux repo:
apiVersion:kustomize.toolkit.fluxcd.io/v1kind:Kustomizationmetadata:name:nfs-subdirnamespace:flux-systemspec:interval:15mpath:nfs-subdirprune:true# remove any elements later removed from the above pathtimeout:2m# if not set, this defaults to interval duration, which is 1hsourceRef:kind:GitRepositoryname:flux-systemhealthChecks:-apiVersion:apps/v1kind:Deploymentname:nfs-subdir-external-provisionernamespace:nfs-suibdir
ConfigMap
Now we're into the nfs-subdir-specific YAMLs. First, we create a ConfigMap, containing the entire contents of the helm chart's values.yaml. Paste the values into a values.yaml key as illustrated below, indented 4 spaces (since they're "encapsulated" within the ConfigMap YAML). I create this example yaml in my flux repo:
apiVersion:v1kind:ConfigMapmetadata:name:nfs-subdir-helm-chart-value-overridesnamespace:nfs-subdirdata:values.yaml:|-# <upstream values go here>
Values you will want to change from the default are:
nfs:server:path:mountOptions:
HelmRelease
Finally, having set the scene above, we define the HelmRelease which will actually deploy the provider into the cluster. I save this in my flux repo:
/nfs-subdir/helmrelease-nfs-subdir.yaml
apiVersion:helm.toolkit.fluxcd.io/v2beta1kind:HelmReleasemetadata:name:nfs-subdirnamespace:nfs-subdirspec:chart:spec:chart:nfs-subdir-external-provisionerversion:4.X.XsourceRef:kind:HelmRepositoryname:nfs-subdirnamespace:flux-systeminterval:15mtimeout:5mreleaseName:nfs-subdir-external-provisionervaluesFrom:-kind:ConfigMapname:nfs-subdir-helm-chart-value-overridesvaluesKey:values.yaml# This is the default, but best to be explicit for clarity
Install the provider.
Commit the changes to your flux repository, and either wait for the reconciliation interval, or force a reconcilliation using flux reconcile source git flux-system. You should see the kustomization appear...
What have we achieved? We have a storage provider that can use an NFS server as it's storage backend, useful for large files, such as media for the autopirate recipe!
Summary
Created:
We have a new storage provider
Chef's notes 📓
The reason I shortened it is so I didn't have to type nfs-subdirectory-provider each time. If you want that sort of pain in your life, feel free to change it! ↩
Tip your waiter (sponsor) 👏
Did you receive excellent service? Want to compliment the chef? (..and support development of current and future recipes!) Sponsor me on Github / Ko-Fi / Patreon, or see the contribute page for more (free or paid) ways to say thank you! 👏
Employ your chef (engage) 🤝
Is this too much of a geeky PITA? Do you just want results, stat? I do this for a living - I'm a full-time Kubernetes contractor, providing consulting and engineering expertise to businesses needing short-term, short-notice support in the cloud-native space, including AWS/Azure/GKE, Kubernetes, CI/CD and automation.
Want to know now when this recipe gets updated, or when future recipes are added? Subscribe to the RSS feed, or leave your email address below, and we'll keep you updated.