Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kubernetes persistente volume: hostpath vs local and data persistence

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?

like image 788
Marco Avatar asked Aug 19 '20 15:08

Marco


People also ask

Is hostPath volume persistent?

Statically provisioning hostPath volumes Used to bind persistent volume claim requests to this persistent volume. The volume can be mounted as read-write by a single node. The configuration file specifies that the volume is at /mnt/data on the cluster's node.

What is the difference between persistent volume and persistent volume claim in Kubernetes?

PVCs are requests for those resources and also act as claim checks to the resource. So a persistent volume (PV) is the "physical" volume on the host machine that stores your persistent data. A persistent volume claim (PVC) is a request for the platform to create a PV for you, and you attach PVs to your pods via a PVC.

What are the types of Kubernetes persistent volume access modes?

22, Kubernetes offered three access modes for PVs and PVCs: ReadWriteOnce – the volume can be mounted as read-write by a single node. ReadOnlyMany – the volume can be mounted read-only by many nodes. ReadWriteMany – the volume can be mounted as read-write by many nodes.

What is the difference between PV and PVC in Kubernetes?

The Difference Between PVs and PVCs in Kubernetes PVs are created by the cluster administrator or dynamically by Kubernetes, whereas users/developers create PVCs. PVs are cluster resources provisioned by an administrator, whereas PVCs are a user's request for storage and resources.

How does local persistent volume work in Kubernetes?

Kubernetes local persistent volume they work well in clustered Kubernetes environments without the need to explicitly bind a POD to a certain node. However, the POD is bound to the node implicitly by referencing a persistent volume claim that is pointing to the local persistent volume.

What is the difference between hostpath and local persistent volumes?

With HostPath volumes, a pod referencing a HostPath volume may be moved by the scheduler to a different node resulting in data loss. But with Local Persistent Volumes, the Kubernetes scheduler ensures that a pod using a Local Persistent Volume is always scheduled to the same node.

Does Kubernetes hostpath work with persistentvolume?

Please note, as per kubernetes docs, HostPath (Single node testing only – local storage is not supported in any way and WILL NOT WORK in a multi-node cluster) PersistentVolume It does work in my case. Show activity on this post.

How many volumes do I need to create a Kubernetes cluster?

For the default minimum cluster size (default scale, no high availability) you must create at least 24 persistent volumes. For an example of how to create persistent volumes by using a local provisioner, see Create a Kubernetes cluster using Kubeadm.


1 Answers

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:

  • https://kubernetes.io/docs/concepts/storage/volumes/#hostpath
  • https://vocon-it.com/2018/12/20/kubernetes-local-persistent-volumes/
like image 173
Kamol Hasan Avatar answered Oct 02 '22 06:10

Kamol Hasan