subPath Mounts

A ConfigMap is updated, and one container of the Pod soon reads the new config while another keeps the old file until a restart, although both mount the same volume. Why does that file miss the update?

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

subPath Mounts, Kubernetes diagram

subPath Mounts, step by step

  1. The web container mounts the whole config volume as a directory at /etc/app. Every read of app.conf goes through the ..data symlink, which points at the v1 directory, so web reads app.conf v1.

    Play from step 1
  2. The proxy container needs only app.conf, and in /etc/nginx, next to the files its image ships. Mounting the whole volume there would hide those files, so proxy sets subPath: app.conf. When the container starts, Kubelet resolves that path to the v1 file and bind-mounts the file itself.

    Play from step 2
  3. The ConfigMap changes, but Kubelet does not edit the files in place. On its next sync it writes the new version into a fresh v2 directory, flips ..data to point at that directory, then deletes the v1 directory.

    Play from step 3
  4. The web container reads app.conf again. Its path to the file still runs through ..data, so the same read now resolves into the v2 directory and web gets the new config without a restart.

    Play from step 4
  5. Proxy reads app.conf too. But its bind mount never goes through ..data and still holds the v1 file, readable although its directory is deleted. So proxy gets v1. For ConfigMap, Secret, downward API and projected volumes alike, the docs say a subPath mount does not receive updates. Proxy sees v2 once its container restarts and Kubelet resolves the path again.

    Play from step 5

Sources