We asked Wikipedia. An environment variable is a dynamic-named value that can affect the way running processes will behave on a computer. They are part of the environment in which a process runs.
Kubernetes uses environment variables extensively; where configurations can be set globally.
Stuff you wanna know:
- When you create a Pod, you can set environment variables for the containers that run in the Pod.
- To set environment variables, include the
env
orenvFrom
field in the configuration file. - The environment variables set using the
env
orenvFrom
field override any environment variables specified in the container image. - When you create a Pod, you can set dependent environment variables for the containers that run in the Pod.
- To set dependent environment variables, you can use $(VAR_NAME) in the
value
ofenv
in the configuration file. - Environment variables may reference each other.
- Environment variables that you define in a Pod’s configuration can be used elsewhere in the configuration.
- You can use secrets as environment variables.
- If a container already consumes a Secret in an environment variable, a Secret update will not be seen by the container unless it is restarted.
- You can use environment variables to define arguments.
- You can use container fields as values for environment variables.
- You can define a container environment variable with data from a single or multiple ConfigMaps.
- You can configure all key-value pairs in ConfigMap as container environment variables.
- You can use ConfigMap-defined environment variables in the
command
andargs
of a container using the$(VAR_NAME)
Kubernetes substitution syntax. - Want to see your environment variables?
printenv
is your friend!
More stuff:
- Defining an environment variable for a container — https://kubernetes.io/docs/tasks/inject-data-application/define-environment-variable-container/
- Defining an environment dependent variable for a container — https://kubernetes.io/docs/tasks/inject-data-application/_print/#pg-eff97c25c917cdb414eda016df0e2bca
- Using environment variables inside of your config — https://kubernetes.io/docs/tasks/inject-data-application/_print/#using-environment-variables-inside-of-your-config
- Defining a container environment variable with data from a single ConfigMap — https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#define-a-container-environment-variable-with-data-from-a-single-configmap
- Defining a container environment variable with data from multiple ConfigMaps — https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#define-container-environment-variables-with-data-from-multiple-configmaps
- Configuring all key-value pairs in ConfigMap as container environment variables — https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#configure-all-key-value-pairs-in-a-configmap-as-container-environment-variables
- Using ConfigMap-defined environment variables in Pod commands — https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/#use-configmap-defined-environment-variables-in-pod-commands
- Using Pod fields as values for environment variables — https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/#use-pod-fields-as-values-for-environment-variables
- Exposing pod information to containers through environment variables — https://kubernetes.io/docs/tasks/inject-data-application/environment-variable-expose-pod-information/
- Using environment variable to define arguments — https://kubernetes.io/docs/tasks/inject-data-application/_print/#use-environment-variables-to-define-arguments
- Using secrets as environment variables — https://kubernetes.io/docs/concepts/configuration/secret/#using-secrets-as-environment-variables
- Using container fields as values for environment variables — https://kubernetes.io/docs/tasks/inject-data-application/_print/#use-container-fields-as-values-for-environment-variables
- EnvVar v1 core — https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.24/#envvar-v1-core