K8s by Example: Environment Variables
| Environment variables configure containers at runtime. Kubernetes supports multiple sources: static values, ConfigMaps, Secrets, and the Downward API. Env vars are set at container start and don’t auto-update. |
| pod-env.yaml | |
| Define environment variables directly in the Pod spec. Simple and explicit, but requires redeployment to change values. Use for static config that rarely changes. | |
| pod-env-refs.yaml | |
| Reference ConfigMaps and Secrets for externalized configuration. Use | |
| pod-downward-api.yaml | |
| The Downward API exposes Pod metadata via | |
| pod-labels-env.yaml | |
| Access labels and annotations via the Downward API. Useful for passing deployment info to your application for metrics, tracing, or feature flags. | |
| pod-resource-env.yaml | |
|
| |
| pod-envfrom.yaml | |
|
| |
| pod-env-interpolation.yaml | |
| Env vars can reference other env vars using | |
| Order matters: env vars are evaluated in order. Later vars can reference earlier ones. ConfigMap/Secret refs are resolved before inline values using them. | |