collimarco
collimarco

Reputation: 35460

Kubernetes: when exactly envFrom imports the values from ConfigMap?

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?

Upvotes: 0

Views: 1183

Answers (2)

user140547
user140547

Reputation: 8200

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.

Upvotes: 0

collimarco
collimarco

Reputation: 35460

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).

Upvotes: 1

Related Questions