Kubernetes: when exactly envFrom imports the values from ConfigMap?

11/14/2021

Suppose that I have a Deployment which loads the env variables from a ConfigMap:

spec.template.spec.containers[].envFrom.configMapRef

Now suppose that I change the data inside the ConfigMap.

When exactly are the Pod env variables updated? (i.e. when the app running in a pod sees the new env variables)

For example (note that we are inside a Deployment): 1. If a container inside the pod crashes and it is restarted does it read the new env or the old env? 2. If a pod is deleted (but not its RelicaSet) and it is recreated does it read the new env or the old env?

-- collimarco
kubernetes

2 Answers

11/14/2021

When using a ConfigMap with env variables, the values are not updated. You have to restart the pod.

If you want hot reload, you can mount that ConfigMap as a volume. Then values are updated automatically, however the app has still to watch for that change.

-- user140547
Source: StackOverflow

11/14/2021

After some testing (with v1.20) I see that env variables in Pod template are updated immediately (it's just a reference to external values).

However the container does not see the new env variables... You need at least to restart it (or otherwise delete and recreate the pod).

-- collimarco
Source: StackOverflow