⚡ ~/naveed k8s
⚡ Portfolio Home ✍️ Engineering Blog Deep Dives 🎯 Interview Hub 1,000+ Scenarios ☸️ Kubernetes Mastery Hub 24 Modules 🎮 DevOps Arcade & Quizzes Subnet Blitz ⚡ 🗺️ DevOps Roadmaps PDFs & Guides 🤖 Morpheus Analysis AI Quant ↗ 🛠️ Developer Tools Utilities 🧪 Labs & Experiments 📄 Interactive CV & Certs 🔗 All Links & Socials ⚡ Join The Dispatch (Weekly SRE Newsletter) →
Phase 1 — Fundamentals Module 04 of 24 Free & Open Access

ConfigMaps & Secrets

Complete production curriculum breakdown. Learn core architectural mechanics, study definitions in plain language, practice hands-on labs with the local minikube prod-sim cluster, and test active recall.

04 - ConfigMaps & Secrets

Why this matters

This is how you separate config from container images — the same image should be deployable to dev/staging/prod with different config, no rebuild.

Read this first — Definitions & Explanations

ConfigMap

Stores non-confidential configuration as key/value data (or files). Inject into Pods as:

Use ConfigMaps for app config, feature flags, non-secret URLs, templates.

Secret

Stores sensitive data (passwords, tokens, TLS keys). In etcd, Secrets are base64-encoded by default, not strongly encrypted unless you enable encryption at rest. Still treat them as sensitive and restrict RBAC.

How Pods consume them

  1. env / envFrom — values become environment variables
  2. volumeMounts — keys become files in a directory
    File mounts are often preferred for credentials rotation patterns.

Updates and restarts

Changing a ConfigMap/Secret does not always restart Pods automatically. Env-based injection typically needs a rollout. Some volume mounts can update files in place (with caveats and delays).

Good practice

Official docs (read for detail)

Key Concepts

YouTube search terms

Hands-on lab (on prod-sim)

# ConfigMap as env vars
kubectl create configmap app-config --from-literal=LOG_LEVEL=debug --from-literal=FEATURE_X=on
kubectl run cfgtest --image=busybox --restart=Never --env-from=configmap/app-config -- env
kubectl logs cfgtest | grep -E 'LOG_LEVEL|FEATURE_X'

# ConfigMap as mounted volume
kubectl create configmap nginx-conf --from-file=nginx.conf=<(echo "worker_processes 2;")
kubectl run cfgvol --image=nginx --restart=Never --overrides='
{"spec":{"volumes":[{"name":"conf","configMap":{"name":"nginx-conf"}}],
"containers":[{"name":"cfgvol","image":"nginx","volumeMounts":[{"name":"conf","mountPath":"/etc/nginx/conf.d/custom.conf","subPath":"nginx.conf"}]}]}}'
kubectl exec cfgvol -- cat /etc/nginx/conf.d/custom.conf

# Secrets — prove they're only base64, not encrypted
kubectl create secret generic db-creds --from-literal=password=SuperSecret123
kubectl get secret db-creds -o jsonpath='{.data.password}' | base64 -d
kubectl get secret db-creds -o yaml   # see it's just base64 in etcd unless encryption-at-rest is on

# Check if this cluster has encryption-at-rest configured (it likely does NOT by default)
minikube ssh -p prod-sim
  sudo cat /etc/kubernetes/manifests/kube-apiserver.yaml | grep -i encryption
  exit

Notes

(fill in your own words after watching + labbing)

📋 Self-Assessment Mastery Checklist (4 Competencies)
🧠 Practice Exam Questions (Module 04 MCQs)
⚡ Take Quiz & Save Progress in Tracker

Review these sample exam questions out loud, test your retrieval, and then unlock official scoring in the interactive tracker.

Question 1: ConfigMaps are intended for:
  • A. Sensitive passwords only
  • B. Non-confidential configuration data
  • C. TLS private keys exclusively
  • D. etcd snapshots
✓ Correct Answer: B (Non-confidential configuration data)
Option B ('Non-confidential configuration data') is the standard production architectural best practice.
Question 2: Secrets in Kubernetes are by default:
  • A. Encrypted with a customer KMS key always
  • B. Base64-encoded (not strongly encrypted at rest unless configured)
  • C. Never stored in etcd
  • D. Visible only to kubelet
✓ Correct Answer: B (Base64-encoded (not strongly encrypted at rest unless configured))
Option B ('Base64-encoded (not strongly encrypted at rest unless configured)') is the standard production architectural best practice.
Question 3: You can mount ConfigMap data into a Pod as:
  • A. Only environment variables
  • B. Only files
  • C. Environment variables and/or volume files
  • D. Only annotations
✓ Correct Answer: C (Environment variables and/or volume files)
Option C ('Environment variables and/or volume files') is the standard production architectural best practice.
Question 4: Updating a ConfigMap mounted as a volume typically:
  • A. Never reaches running Pods
  • B. Can update files for many volume mounts (with caveats)
  • C. Restarts the whole cluster
  • D. Deletes the Secret
✓ Correct Answer: B (Can update files for many volume mounts (with caveats))
Option B ('Can update files for many volume mounts (with caveats)') is the standard production architectural best practice.
Question 5: Best practice for production secrets is to:
  • A. Commit them to git
  • B. Use external secret managers / encryption + least privilege RBAC
  • C. Put them in ConfigMaps
  • D. Hardcode in the image
✓ Correct Answer: B (Use external secret managers / encryption + least privilege RBAC)
Option B ('Use external secret managers / encryption + least privilege RBAC') is the standard production architectural best practice.
← Previous Module (03) Services & Cluster Networking Basics Next Module (05) → Storage: Volumes, PV, PVC, StorageClasses