concept hostpath volume in category kubernetes

appears as: hostPath volume, hostPath volume, A hostPath volume, hostPath volumes
Kubernetes in Action

This is an excerpt from Manning's book Kubernetes in Action.

Most pods should be oblivious of their host node, so they shouldn’t access any files on the node’s filesystem. But certain system-level pods (remember, these will usually be managed by a DaemonSet) do need to either read the node’s files or use the node’s filesystem to access the node’s devices through the filesystem. Kubernetes makes this possible through a hostPath volume.

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%@!

6.3.1. Introducing the hostPath volume

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.

sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest