ConfigMap and Secret as Files
A ConfigMap is updated while the app reads its files from a volume, yet on Linux the app never catches a half-written file, and nobody restarts the app. How does the new version land at once, and how soon?
Play the animation 3 steps, animated, plays on a computer or a tablet
ConfigMap and Secret as Files, step by step
-
By default Kubelet watches ConfigMap app on the API server. Before the container starts it writes every key as a file, or only the keys the volume lists in items, into a hidden timestamped directory, then points the ..data symlink at it. The app.conf entry is a symlink to ..data/app.conf. On Linux a Secret volume is built the same way, on tmpfs.
Play from step 1 -
Someone edits ConfigMap app. The watch updates the Kubelet cache, and on its next periodic sync, by default up to about 90 seconds later, Kubelet writes the whole v2 into a second timestamped directory. Nothing points at it yet, so the app still reads v1.
Play from step 2 -
In the same sync, Kubelet points a new ..data_tmp symlink at v2 and renames it over ..data. On Linux the rename is atomic, so opening app.conf gets all of v1 or all of v2, never a mix. Only then is the v1 directory deleted. Nothing restarts the app: the next time it opens app.conf, it reads v2. A subPath mount of app.conf would keep v1 until its container restarts.
Play from step 3