Can I modify container's environment variables without restarting pod using kubernetes

Simply put and in kube terms, you can not.

Environment for linux process is established on process startup, and there are certainly no kube tools that can achieve such goal. For example, if you make a change to your Deployment (I assume you use it to create pods) it will roll the underlying pods.

Now, that said, there is a really hacky solution reported under Is there a way to change the environment variables of another process in Unix? that involves using GDB

Also, remember that even if you could do that, there is still application logic that would need to watch for such changes instead of, as it usually is now, just evaluate configuration from envs during startup.


This worked with me

kubectl set env RESOURCE/NAME KEY_1=VAL_1 ... KEY_N=VAL_N

check the official documentation here


I'm not aware of any way to do it and I can't think of real world scenario where this makes too much sense.

Usually you have to restart a process for it to notice the changed environment variables and the easiest way to do that is restart the pod.

The solution closest to what seem to want is to create a deployment and then use kubectl edit (kubectl edit deploy/name) to modify it's environment variables. A new pod is started and the old one is terminated after you save.

Tags:

Kubernetes