Keyboard Shortcuts N Next post
P Previous post
S Save / unsave
R Read aloud
T Toggle theme
/ Focus search
Esc Close panels
🔥
Ready to read...
K8s Config Kubernetes Kubernetes: From Zero to Production Module 5 - Config and Storage

ConfigMaps - Configuration Management in K8s

Reviewed & accurate
AI Summary

What You Will Learn

Beginner

  • What ConfigMaps are
  • How to create and use them
  • Injecting config into Pods
configmap.yamlyaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: app-config
data:
  DB_HOST: "postgres.default.svc.cluster.local"
  DB_PORT: "5432"
  LOG_LEVEL: "info"
  config.yaml: |
    database:
      host: postgres
      port: 5432
    logging:
      level: info

Using ConfigMaps in Pods

Terminalyaml
# Method 1: As environment variables
spec:
  containers:
  - name: app
    image: my-app
    envFrom:
    - configMapRef:
        name: app-config

# Method 2: As a single env var
spec:
  containers:
  - name: app
    env:
    - name: DB_HOST
      valueFrom:
        configMapKeyRef:
          name: app-config
          key: DB_HOST

# Method 3: As a file (volume)
spec:
  containers:
  - name: app
    volumeMounts:
    - name: config
      mountPath: /etc/config
  volumes:
  - name: config
    configMap:
      name: app-config
Why ConfigMaps?
Without ConfigMaps: config is baked into the image. Need to change a DB host? Rebuild the image. With ConfigMaps: change the ConfigMap, restart the Pod. Same image works in dev/staging/prod.

Practical Exercise

Create a ConfigMap with DB_HOST and DB_PORT
Apply: kubectl apply -f configmap.yaml
Create a Pod that uses envFrom to load it
Exec in: kubectl exec -it pod -- env | grep DB
Verify the values are injected

Key Takeaways

  • ConfigMap = key-value config data (non-sensitive).
  • Three ways to use: envFrom (all), valueFrom (one), volume (file).
  • Separates config from image - same image for dev/prod.
  • ConfigMaps are NOT for secrets - use Secrets instead.
  • Changing ConfigMap requires Pod restart to take effect.
Previously: Module 4 covered networking.
Today: You learned: Separate config from code with ConfigMaps.
Next: Lesson 27 covers Secrets.
Test Your Knowledge
How did you find this?

Comments

Join the discussion! Sign in with your Google or Blogger account, or comment as Anonymous - no account needed. For quick questions, also reach me on Telegram @cytestch.

Comments