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

Another approach for runtime pods you can get into the Pod command line and change the variables in the runtime RUN kubectl exec -it <pod_name> -- /bin/bash Then Run export VAR1=VAL1 && export VAR2=VAL2 && your_cmd