Pod Volume Model
An init container writes a file and exits, then the app crashes and restarts, yet the other containers of the Pod still find the file. Who does it belong to, and how long does it last while containers come and go?
Play the animation 6 steps, animated, plays on a computer or a tablet
Pod Volume Model, step by step
-
The Pod spec names one emptyDir volume, cache, under spec.volumes. It belongs to the Pod, not to a container: it is created empty when the Pod is assigned to a Node, before any container starts. Its bar starts with the Pod bar.
Play from step 1 -
The init container seed runs first, to completion. Its own volumeMounts entry puts cache at /work, where it writes config.json, then it exits. The seed bar ends and the mount goes with the container, but the file stays in the volume.
Play from step 2 -
Now app and log-shipper start, and each lists cache in a volumeMounts entry of its own. For app it is /data, for log-shipper /logs with readOnly set. App opens /data/config.json and finds the file seed left, although seed no longer runs.
Play from step 3 -
Both containers see the same bytes under different paths. App writes app.log into /data, and log-shipper reads that very file at /logs through a mount that cannot write. That is the usual way two containers of one Pod share files.
Play from step 4 -
App crashes and, under restartPolicy Always, the default, is restarted in the same Pod, so its restart count goes to 1. The new container starts clean outside the volume, yet it mounts the same cache at /data and app.log is still there.
Play from step 5 -
No container bar spans the whole story, and none of them ever owned the volume. The cache bar matches the Pod bar: this emptyDir lasts until the Pod leaves its Node, however many containers come and go inside it.
Play from step 6