Difference between NFS-PV, hostPath-PV on NFS and hostPath mount in deployment Difference between NFS-PV, hostPath-PV on NFS and hostPath mount in deployment kubernetes kubernetes

Difference between NFS-PV, hostPath-PV on NFS and hostPath mount in deployment


The NFS is indeed the preferred solution:

An nfs volume allows an existing NFS (Network File System) share tobe mounted into a Pod. Unlike emptyDir, which is erased when a Podis removed, the contents of an nfs volume are preserved and thevolume is merely unmounted. This means that an NFS volume can bepre-populated with data, and that data can be shared between pods. NFScan be mounted by multiple writers simultaneously.

So, an NFS is useful for two reasons:

  • Data is persistent.

  • It can be accessed from multiple pods at the same time and the data can be shared between pods.

See the NFS example for more details.

While the hostPath:

A hostPath volume mounts a file or directory from the host node'sfilesystem into your Pod.

Pods with identical configuration (such as created from a PodTemplate)may behave differently on different nodes due to different files onthe nodes

The files or directories created on the underlying hosts are onlywritable by root. You either need to run your process as root in aprivileged Container or modify the file permissions on the host to beable to write to a hostPath volume

hostPath is not recommended due to several reasons:

  • You don't directly control which node your pods will run on, so you're not guaranteed that the pod will actually be scheduled on the node that has the data volume.

  • You expose your cluster to security threats.

  • If a node goes down you need the pod to be scheduled on other node where your locally provisioned volume will not be available.

the hostPath would be good if for example you would like to use it for log collector running in a DaemonSet. Other than that, it would be better to use the NFS.