Configure an app with ConfigMaps and Secrets

DevOps, Hands On25 minutesFreeSteps checked 23 November 2026By Cloud Hands On

In this task you'll keep settings and passwords out of the image and change them without rebuilding.

A ConfigMap holds plain settings and a Secret holds sensitive ones (base64-encoded, which is not encryption). A pod can read either as environment variables or as files in a mounted volume. Environment variables are fixed when the container starts; mounted files update in place a minute or two after the ConfigMap changes, if the app re-reads them.

So a settings change needs a plan: either the app watches its files, or you restart the deployment (kubectl rollout restart), or you put a hash of the config in the pod template so any change rolls the pods. Real secrets are better kept in a vault (such as Azure Key Vault with the CSI driver) and secrets at rest should be encrypted.

Example. SS Kaiser's shop front reads its feature flags from a mounted ConfigMap and reloads them every minute, so marketing can switch a banner on without a release. Its payment key comes from Key Vault, not from a Secret in Git.

Before you start

You need: Docker Desktop, kind and kubectl on your computer (all free), and a cluster from Run a practice cluster on your computer. Time: 25 minutes.

Where to look

  1. Terminal
  2. kubectl

Steps

  1. Create a ConfigMap shop-config with LOG_LEVEL=info and BANNER=off, and a Secret shop-secret with API_KEY=example-only.
  2. Run a deployment that loads the ConfigMap with envFrom and mounts it as files at /config.
  3. Check both with kubectl exec (env, and cat /config/BANNER).
  4. Change BANNER to on; within a minute or two the file shows on, but the environment variable still says off.Env is read once at start.
  5. Run kubectl rollout restart deployment shop and check the variable again.
  6. Decode the Secret with kubectl get secret shop-secret -o jsonpath='{.data.API_KEY}' | base64 -d to see why it isn't encryption.

Commands

kubectl create configmap shop-config --from-literal=LOG_LEVEL=info --from-literal=BANNER=off
kubectl create secret generic shop-secret --from-literal=API_KEY=example-only
kubectl create deployment shop --image=nginx:1.27
kubectl set env deployment/shop --from=configmap/shop-config
kubectl rollout restart deployment shop
kubectl get secret shop-secret -o jsonpath='{.data.API_KEY}' | base64 -d

Watch out for

Cost
Free.
Security
Anyone who can read Secrets in a namespace can read every password there. Limit get on secrets, encrypt etcd, and prefer a vault for real credentials.
Common mistakes
Committing Secret YAML to Git, expecting env vars to update without a restart, and using subPath mounts (they never update).

Clean up

Delete the deployment, ConfigMap and Secret.

Words to know

ConfigMap
A Kubernetes object holding plain settings for pods.
Secret
Like a ConfigMap, for sensitive values; encoded, not encrypted, by default.
envFrom
Loads every key of a ConfigMap or Secret as environment variables.
rollout restart
Replaces a deployment's pods gradually so they pick up new settings.

Tick off each step and track your progress in the guide.

Open this task in DevOps, Hands On

Keep going