Configuration with ConfigMaps & Secrets
Keep config out of your images. Store settings in a ConfigMap and sensitive values in a Secret, then inject both into a pod as environment variables and prove they arrived inside the container.
- Intermediate
- 45 min
- Kubernetes
- ConfigMaps
- Secrets
- DevOps
Overview
A good container image carries no environment-specific config — the same image runs in dev, staging and prod, configured from the outside. Kubernetes provides two objects for exactly this: ConfigMaps for plain settings and Secrets for sensitive values, both injected into pods at runtime.
In this lab you'll create a ConfigMap and a Secret, then write a Pod manifest that pulls values from each into the container's environment — and finally exec into the running pod to confirm the values actually arrived. This is how real applications get their database URLs, feature flags and API keys.
What you will learn
- Create a ConfigMap from literal key/value settings
- Create a Secret for sensitive values
- Reference a ConfigMap and a Secret from a Pod manifest
- Inject configuration into a container as environment variables
- Verify configuration inside a running pod with
kubectl exec
Before you start
- Deploy, Expose & Scale an App first, or kubectl basics
- Comfortable editing a YAML file
Tasks
- 01Create a ConfigMap
- 02Create a Secret
- 03Inject both into a pod