Take a moment to think about this
If you hardcode a config value (say `API_URL=https://staging.example.com`) into your Docker image, moving from staging to production means rebuilding the image — that's slow and error-prone. With a ConfigMap, you keep the config value as a separate Kubernetes object, and your Pod injects it at run time as an environment variable (or a file) — you can change app behavior just by changing the ConfigMap, without touching the image itself.
Let's connect this to a real scenario
You define a ConfigMap in YAML and pull it into your Pod spec with `envFrom` (all its key-value pairs as env variables) or `volumeMounts` (as a config file). You can keep separate ConfigMaps for staging and production and switch environments just by swapping the ConfigMap, without ever touching the Deployment YAML.
Let's look at it together
apiVersion: v1
kind: ConfigMap
metadata:
name: app-config
data:
API_URL: "https://api.example.com"
LOG_LEVEL: "info"
---
apiVersion: v1
kind: Pod
metadata:
name: app-with-config
spec:
containers:
- name: app
image: my-app:latest
envFrom:
- configMapRef:
name: app-config$ kubectl exec app-with-config -- printenv API_URL
https://api.example.com5-minute try-it
Create a ConfigMap and hook it up to a Pod using envFrom — verify the value showed up with `kubectl exec <pod> -- printenv`.
A quick word of caution
Anyone can read a ConfigMap's data with `kubectl get configmap -o yaml` — never put any sensitive data in a ConfigMap.