Skip to content

NFS-backed storage

Our default Rijkswaterstaat (VSphere) storage backend does not allow for multiple pods to mount a single persistent volume.

However, applications sometimes require such functionality.

This is made possible by using NFS-backed PV(C)s with the help of the NFS Subdir External Provisioner.

To create and use a PV like that, one can create a PVC using the nfs storage class, created by the NFS provider:

pvc-nfs-storage-class-example.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: test-pvc
spec:
storageClassName: nfs
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1Mi

This will give you a PVC that can be mounted by multiple pods. The backing storage is a directory on the dedicated NFS share. This directory is automatically created by the NFS provisioner.

However, you will not know exactly where is the persistent data stored on the NFS share, i.e. what is the name of that directory.

This may be problematic when you want off-cluster processes to store data that your application can use, or if you want to share data between namespaces.

In this situation, it is possible to provide the nfs.io/storage-path annotation to the PVC that directs the provisioner to point your PVC to a particular directory on the NFS share:

nfs-storage-path-example.yaml
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: test-pvc
annotations:
nfs.io/storage-path: "directory-name"
spec:
storageClassName: nfs
accessModes:
- ReadWriteMany
resources:
requests:
storage: 1Mi

By default, all NFS provisioners run with the onDelete: retain setting, which means that when the PVC is deleted, the directory that backs the PV will not be removed from the NFS share. If you create the PVC with the same storage path as before, the provisioner will not create a new directory, but will reuse the existing one.