ConfigMaps & Secrets

💤0
Lv 10 XP
← 📦 Containers & Kubernetes · Kubernetes

ConfigMaps & Secrets

Intermediate ⭐ 80 XP ⏱ 16 min #kubernetes#configmaps#secrets

Separate configuration and sensitive data from container images.

📖Theory

You keep configuration out of images so the same image runs in any environment. Kubernetes provides two objects:

  • ConfigMap — non-sensitive key/value config
  • Secret — sensitive data (passwords, tokens, keys)

Both can be injected into Pods as environment variables or mounted files. Importantly, Kubernetes Secrets are only base64-encoded by default, not encrypted — you must enable encryption at rest and tight RBAC, or use an external secrets manager, to truly protect them.

🌍Real-World Example
apiVersion: v1
kind: ConfigMap
metadata: { name: app-config }
data:
  LOG_LEVEL: "info"
---
apiVersion: v1
kind: Secret
metadata: { name: app-secret }
type: Opaque
stringData:
  DB_PASSWORD: "s3cr3t"     # stringData is auto base64-encoded
# Inject into a Pod
envFrom:
  - configMapRef: { name: app-config }
  - secretRef:    { name: app-secret }
✍️Hands-On Exercise
  1. Create a ConfigMap and inject it as environment variables.
  2. Create a Secret and mount it as a file in a Pod.
  3. Explain why a Kubernetes Secret is not truly secure by default.
  4. Name two ways to strengthen Secret protection.
🧾Cheat Sheet
ObjectUse
ConfigMapNon-sensitive config
SecretSensitive data (base64)
envFromInject all keys as env vars
volume mountInject as files
Encryption at restProtect Secrets in etcd
RBACLimit who can read Secrets
External storeVault / cloud secret manager
💬Common Interview Questions
What's the difference between a ConfigMap and a Secret?

Both inject configuration into Pods, but ConfigMaps hold non-sensitive data while Secrets hold sensitive data with base64 encoding and tighter access controls.

Are Kubernetes Secrets encrypted?

Not by default — they’re only base64-encoded. You must enable encryption at rest in etcd and restrict access via RBAC (or use an external secrets manager) to secure them.

📚Official Documentation

📝 My notes on this topic

Auto-saves as you type