Thuta Learning
IntermediateDevOpsintermediate

ConfigMaps

Relax. We'll talk through this in plain words — no textbook voice.

What you'll walk away with

  • Understand ConfigMaps without any of the intimidation
  • Get comfortable running kubectl commands and YAML yourself
  • Apply this concept right away in a real project

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

yaml
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
You should see
$ kubectl exec app-with-config -- printenv API_URL
https://api.example.com

5-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.

Easy traps

  • Putting passwords/API keys into a ConfigMap — data in a ConfigMap is plain text, not encrypted (use a Secret instead)
  • Assuming an updated ConfigMap value shows up instantly without restarting the Pod — if you're using envFrom, the Pod needs to be recreated/restarted before it picks up the new value

Now try it yourself

Create a ConfigMap and hook it up to a Pod using envFrom — verify the value showed up with `kubectl exec <pod> -- printenv`.

You'll know it worked when: $ kubectl exec app-with-config -- printenv API_URL https://api.example.com

ConfigMaps | Thuta Learning