๐Ÿ“– Read-only preview โ€” lessons, diagrams, and quizzes only. The hands-on labs, live grading, and progress tracking require running the real course locally against a Kubernetes cluster.Run it locally โ†’

Module 5 ยท Lesson 5.1

ConfigMaps

Config doesn't belong inside the image

Baking config into a container image means rebuilding the image every time a setting changes โ€” the same mistake as hardcoding a database hostname into a compiled binary. A ConfigMap is a plain key-value object you create separately from your Pods, so the same image can run in dev, staging, and prod with different config, unchanged.

Three ways to consume one

  1. A single env var, via valueFrom.configMapKeyRef โ€” pick one key out of the ConfigMap and expose it as one environment variable. Good for a handful of simple values.
  2. envFrom โ€” dump every key in the ConfigMap into env vars at once, no per-key wiring. Convenient, but less explicit about what a Pod actually depends on.
  3. A mounted volume โ€” the whole ConfigMap appears as a directory, one file per key, its contents as the file's content. This is the only option that fits large config (an actual nginx.conf, a JSON blob) or files an app expects to literally read from disk.

The option that matters most in practice: env vars are frozen at pod start. Change the ConfigMap, and existing pods keep their old env vars until they're recreated. A mounted volume, by contrast, does get updated in the running pod (kubelet syncs it periodically) โ€” but most apps don't watch their config files for changes, so you still usually need to restart the pod to actually pick it up. Either way: updating a ConfigMap is not the same as updating what your app is doing right now.

Linux aside: environment variables and files

If you've ever set export FOO=bar in a shell, that's exactly what valueFrom/envFrom are doing to the container's single process before it starts โ€” same mechanism, just set by the kubelet instead of your terminal. A volume mount, meanwhile, is Kubernetes doing the same thing your OS does when you mount a USB drive at /mnt/usb: an existing directory path suddenly has new file contents behind it, fully transparent to whatever reads from that path.

The infrastructure analogy

Think of a ConfigMap as the externalized .env file or /etc/app/config you'd manage with Ansible/Puppet in a traditional deploy โ€” except here it's a first-class, versioned API object the Pod spec references directly, instead of a file pushed out-of-band and hoped to be in sync.

In the lab, you'll diagnose a Pod whose environment doesn't match what its ConfigMap actually contains โ€” the same "which part has the stale value" debugging you've likely done with config-management drift before.

๐Ÿงช Lab: lab-09-configmaps

Preview only

Goal

Wire a ConfigMap into a Deployment, then diagnose a container that never starts because of a key name mismatch.

Tasks

  1. Apply the starting manifests: kubectl apply -f manifests/
  2. Check the pod: kubectl get pods -n lab-09-configmaps. It's not Running โ€” note the status.
  3. kubectl describe pod -n lab-09-configmaps -l app=app โ€” read the Events at the bottom. It names the exact problem.
  4. Compare against the ConfigMap's real keys: kubectl get configmap app-config -n lab-09-configmaps -o yaml
  5. Fix it: edit manifests/deployment.yaml so the configMapKeyRef.key for DATABASE_HOST matches a key that actually exists in the ConfigMap, then kubectl apply -f manifests/deployment.yaml again. (Editing a Deployment's env and reapplying is fine โ€” unlike a bare Pod, a Deployment's container spec is meant to be changed; it just rolls a new pod out.)
  6. Confirm: kubectl get pods -n lab-09-configmaps shows Running, and kubectl exec -n lab-09-configmaps deploy/app -- printenv DATABASE_HOST prints the ConfigMap's value.

Check

Run the check once the pod is Running and DATABASE_HOST resolves correctly inside the container.

This lab runs against a real local Kubernetes cluster with an automated grader โ€” clone the repo and run make start to do it for real.

๐Ÿ“ Quiz

1. Why use a ConfigMap instead of baking config into the container image?

2. Which ConfigMap consumption method is the only one that fits a large config file like a full nginx.conf?

3. You update a ConfigMap that's consumed via a normal env var (configMapKeyRef). An already-running Pod using it does NOT see the new value. Why?scenario

4. What's the practical difference between envFrom and a single configMapKeyRef env var?

5. A Pod's env references `configMapKeyRef` with key DATABASE_HOST, but the ConfigMap's actual key is DB_HOST. What happens when the Pod starts?scenario

Progress isn't saved in this preview โ€” run the course locally to track completion and grade labs for real.