My previous article “Inotify in Containers” has demonstrated that when ConfigMap is mounted as directories, any changes in the ConfigMap will propagate to related pods.
A follow-up question might be: what if the ConfigMap is mounted as environment variables?
Some said that the answer is NO in Kubernetes1; even in the old Docker world2. Therefore, I'd like to begin with a simple experiment to try to answer the question: After a container starts, will it see any changes of environment variables?
The experiment material is available at https://github.com/William-Yeh/container-and-env , and here's a simple demo:
It is obvious in the demo that the changes of environment variables will not affect already-running processes inside the containers — let alone pods in the Kubernetes world.
To simply put, if you want ConfigMap to propagate its changes to related pods, mount the ConfigMap as directories, not environment variables.
Series of Articles
❷ Containers and Environment Variables
A good Q&A in Stack Overflow: Reload configuration when env variable has changed. ↩︎