concept hostpath in category kubernetes

This is an excerpt from Manning's book Kubernetes in Action.
hostPath—Used for mounting directories from the worker node’s filesystem into the pod.
A hostPath volume points to a specific file or directory on the node’s filesystem (see figure 6.4). Pods running on the same node and using the same path in their hostPath volume see the same files.
Figure 6.4. A hostPath volume mounts a file or directory on the worker node into the container’s filesystem.
![]()
hostPath volumes are the first type of persistent storage we’re introducing, because both the gitRepo and emptyDir volumes’ contents get deleted when a pod is torn down, whereas a hostPath volume’s contents don’t. If a pod is deleted and the next pod uses a hostPath volume pointing to the same path on the host, the new pod will see whatever was left behind by the previous pod, but only if it’s scheduled to the same node as the first pod.
If you’re thinking of using a hostPath volume as the place to store a database’s data directory, think again. Because the volume’s contents are stored on a specific node’s filesystem, when the database pod gets rescheduled to another node, it will no longer see the data. This explains why it’s not a good idea to use a hostPath volume for regular pods, because it makes the pod sensitive to what node it’s scheduled to.
Let’s see how a hostPath volume can be used properly. Instead of creating a new pod, let’s see if any existing system-wide pods are already using this type of volume. As you may remember from one of the previous chapters, several such pods are running in the kube-system namespace. Let’s list them again:
Listing 6.3. A pod using hostPath volumes to access the node’s logs
$ kubectl describe po fluentd-kubia-4ebc2f1e-9a3e --namespace kube-system Name: fluentd-cloud-logging-gke-kubia-default-pool-4ebc2f1e-9a3e Namespace: kube-system ... Volumes: varlog: Type: HostPath (bare host directory volume) Path: /var/log varlibdockercontainers: Type: HostPath (bare host directory volume) Path: /var/lib/docker/containers !@%STYLE%@! {"css":"{\"css\": \"font-weight: bold;\"}","target":"[[{\"line\":0,\"ch\":0},{\"line\":0,\"ch\":73}],[{\"line\":5,\"ch\":2},{\"line\":5,\"ch\":9}],[{\"line\":6,\"ch\":4},{\"line\":6,\"ch\":53}],[{\"line\":9,\"ch\":4},{\"line\":9,\"ch\":53}],[{\"line\":7,\"ch\":4},{\"line\":7,\"ch\":24}],[{\"line\":8,\"ch\":2},{\"line\":8,\"ch\":25}],[{\"line\":6,\"ch\":4},{\"line\":6,\"ch\":53}],[{\"line\":9,\"ch\":4},{\"line\":9,\"ch\":53}],[{\"line\":10,\"ch\":4},{\"line\":10,\"ch\":42}]]"} !@%STYLE%@!