Understand Volumes in Kubernetes: emptyDir vs hostPath
Scenario
Your team is choosing volume types for a new workload. Before they decide, they want to see where Kubernetes really keeps the data of an emptyDir volume and of a hostPath volume, and who manages each directory on the node.
You will run a small volume-explorer Pod with both volume types, then go to the node where it runs and find the directory that holds the emptyDir data.
The cluster has two nodes: cplane-01, the control plane, and node-01, a worker. kubectl is configured on cplane-01.

Figure: emptyDir and hostPath volume architecture showing mount points, lifecycle, and storage locations on the Kubernetes node.
Task
Create a Pod named volume-explorer in the namespace storage-lab:
| Setting | Requirement |
|---|---|
| Container name | explorer |
| Image | busybox:stable |
Volume cache-vol | emptyDir, mounted at /cache |
Volume node-vol | hostPath with the path /tmp/k8s-node-data, mounted at /node-data |
Use this command for the container. It writes one file to each volume and keeps the container running:
command:
- /bin/sh
- -c
- |
echo 'cache volume data' > /cache/cache.log &&
echo 'hostpath volume data' > /node-data/node.log &&
sleep 3600
When the Pod is running, find the directory on the node where Kubernetes keeps the data of the emptyDir volume cache-vol. Enter its full path in the last test case below.
Hint 1: Defining the volumes
A volume is defined once under spec.volumes, and each container that uses it mounts it by name under volumeMounts:
kubectl explain pod.spec.volumes.emptyDir
kubectl explain pod.spec.volumes.hostPath
kubectl explain pod.spec.containers.volumeMounts
Docs:
Hint 2: Finding the emptyDir data on the node
The kubelet on the node where the Pod runs creates the emptyDir directory. Find out which node that is:
kubectl get pod <name> -n <namespace> -o wide
The kubelet keeps one directory per Pod, named after the Pod UID, under its root directory /var/lib/kubelet. The UID is in the Pod metadata:
kubectl explain pod.metadata.uid
Connect to the node with ssh <node>. The first connection asks you to confirm the host key of the node. The kubelet directory is readable only by root, so use sudo to look inside it.
Docs:
- emptyDir (Kubernetes)
Hint 3: When the Pod does not start
The volumes and mounts of a Pod cannot be changed after it is created. Fix the manifest, delete the Pod and create it again. The events at the end of the describe output show why a Pod is not running:
kubectl describe pod <name> -n <namespace>