Kubernetes persistente volume: hostpath vs local and data persistence

8/19/2020

What is the main difference between hostpath and local persistent volume in Kubernetes? Assuming I have a kubernetes cluster running on my machine with a pod running a database that uses a local persistent volume to save data, if the whole cluster fail (for example shutting down the machine), at the next start of the machine (and cluster) there would no longer be a trace of the data previously saved by the pod in the persistent volume, is that correct?

-- Marco
data-persistence
database
kubernetes
persistent-volumes

1 Answer

8/19/2020

A hostPath volume mounts a file or directory from the host node's filesystem into your Pod. So, if you have a multi-node cluster, the pod is restarted for some reasons and assigned to another node, the new node won't have the old data on the same path. That's why we have seen, that hostPath volumes work well only on single-node clusters.

Here, the Kubernetes local persistent volumes help us to overcome the restriction and we can work in a multi-node environment with no problems. It remembers which node was used for provisioning the volume, thus making sure that a restarting POD always will find the data storage in the state it had left it before the reboot.

Once a node has died, the data of both hostpath and local persitent volumes of that node are lost.

Ref:

-- Kamol Hasan
Source: StackOverflow