liveBook · Manning

Hostpath volume

As explained in Kubernetes in Action, Second Edition

A hostPath is a Kubernetes volume type that mounts a file or directory from a worker node into a pod.

A hostPath volume mounts a specific file or directory from a worker node’s filesystem into a pod. Most application pods should not depend on node-local files; system-level pods may need them to read logs, access devices, or interact with node components. section 9.4 section 9.4.1

Host-local storage has several important operational properties:

  • Pods using the same hostPath on the same node can access the same files, while pods on other nodes cannot. section 9.4.1
  • A database can lose access to its data after rescheduling unless it is kept on the same node, so hostPath is not generally suitable for database storage. section 9.4.1
  • The optional type setting checks whether the path is a directory, file, block device, character device, or UNIX socket; creation variants can create missing files or directories. section 9.4.2
  • Unrestricted hostPath access is dangerous because a pod may modify node configuration, run processes on the node, or expose the Docker socket. section 9.4.1

Mounting the node root

A pod can define hostPath.path as / and mount it at /host. After applying the manifest, kubectl exec -it node-explorer -- sh opens a shell; cd /host reaches the worker node’s root filesystem. This deliberately dangerous example demonstrates why hostPath use requires care. section 9.4.2

Figure 9.14 A hostPath volume mounts a file or directory from the worker node’s filesystem into the container.
figure

Shows how a hostPath volume maps a worker-node file or directory into a container. section 9.4.1

How Kubernetes in Action, Second Edition covers it

How deep it goes
Defines node-local mounting, sharing behavior, path types, creation rules, scheduling implications, and security risks.
Examples
Demonstrates mounting the node root at /host in an Alpine pod and exploring it with kubectl exec.
What you can do after
Operate/configure hostPath mounts with paths and type checks while recognizing node-local persistence and security hazards.
How it connects
Connects volumes to pods and containers, node scheduling to data availability, and privileged access to cluster security.

Also explained in

Compare how 2 books explain hostpath volume →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kubernetes in Action, Second Edition. The section links point to the parts of the book it draws on.