Context
The Kubernetes Pod specification allows defining environment variables through the use of the env
and envFrom
fields. These variables are then accessible at runtime to the processes running in the container, alongside the variables declared in the image. If the same variable is defined in multiple sources, then the order of precedence determines what the environment variable value will be during container execution.
How to
The order of precedence for environment variables is as follows:
- Keys in
env
field - Keys in
envFrom
field - Keys defined in the container image
If there are multiple occurrences of a variable in either env
or envFrom
fields, then the last key occurrence within each block takes precedence.