Where Volume Data Lives

A Pod keeps data in its container and five volumes, two emptyDir, a hostPath, a ConfigMap and a PVC. A container restart, a deleted Pod and a lost Node each take a part. Where do these six keep it, and how long?

Play the animation 7 steps, animated, plays on a computer or a tablet

Where Volume Data Lives, Kubernetes diagram

Where Volume Data Lives, step by step

  1. The app writes /tmp/report, a path no volume covers, so the bytes land in the writable layer of its own container. That layer sits on the Node storage, here its disk, but it belongs to that one container and to nothing else. It is the shortest lived home on this map.

    Play from step 1
  2. Three volumes keep their bytes on the Node. The emptyDir cache and the hostPath node-logs are directories on its storage, here its disk. The emptyDir scratch sets medium Memory, a tmpfs in Node RAM, and what it holds counts against the memory limit of the container that writes it.

    Play from step 2
  3. The config volume is a ConfigMap, an API object the API server stores in ETCD. Kubelet fetches the ConfigMap and writes each key into the Pod as a read-only file, so the app reads a copy. A Secret volume arrives the same way, into a tmpfs in RAM.

    Play from step 3
  4. The data volume is a PersistentVolumeClaim. Here the claim is bound to network storage, so its bytes live outside the Node entirely, reached over the network. Neither the Pod nor the Node owns that disk, and the data lasts at least as long as the claim that points at it.

    Play from step 4
  5. The app container crashes and Kubelet restarts it. The new container gets a fresh writable layer, so /tmp/report is gone and it starts clean. All five volumes are untouched, because none of them belonged to the container.

    Play from step 5
  6. Now the Pod is deleted. The emptyDir volumes cache and scratch are deleted with it, and the config files Kubelet wrote are removed. The ConfigMap object stays in the API server, the claim still holds its data, and node-logs stays on the Node disk.

    Play from step 6
  7. Finally the Node itself is lost, disk and all, and everything that lived on it goes too, node-logs included: a hostPath lasts only as long as that one Node disk. The ConfigMap and the claim data survive because they never lived on the Node.

    Play from step 7

Sources