How to configure NFS shared volume for Kubernetes pods

If you have replications of a pod, that all need to access a shared data storage, NFS volume is one of the options.

In order to configure the storage, you need an NFS server access for your K8s cluster.


Usually you will have a remote NFS storage that your cluster uses. On that remote NFS server you get a dedicated storage space under a certain path on the file system.


Now using the NFS server hostname and the path of your remote storage, you can create a PersistentVolume for your cluster:


apiVersion: v1

kind: PersistentVolume

metadata:

name: my-app-pv

spec:

capacity:

storage: 5Gi

volumeMode: Filesystem

accessModes:

- ReadWriteMany

persistentVolumeReclaimPolicy: Recycle

storageClassName: manual

mountOptions:

- hard

- nfsvers=4.0

nfs:

server: nfs-server-hostname

path: /path/on/nfs/server


And to make use of that PV in your pods, you also need to create a PersistentVolumeClaim:


kind: PersistentVolumeClaim

apiVersion: v1

metadata:

name: my-app-pvc

spec:

storageClassName: manual

volumeName: my-app-pv

volumeMode: Filesystem

accessModes:

- ReadWriteMany

resources:

requests:

storage: 3Gi


Now all you need to do is reference the PersistentVolumeClaim in your application's deployment configuration and mount it into the pods. This way each pod of your application will get access to this shared storage on the NFS server. So what one pod writes to it will be visible for another to read and vice versa.

Nicole Hiller  |  Nana Janashia

Mail: info@nnsoftware.at

©2018 by nnSoftware

This site was designed with the
.com
website builder. Create your website today.
Start Now