What are ConfigMaps and Secrets in Kubernetes?
In one line: ConfigMaps store non-sensitive configuration (like URLs and feature settings) and Secrets store sensitive values (like passwords and API keys), so configuration is kept separate from the container image.
Why separate config from images: the same image should run in dev, staging and production ("build once, deploy many"). Only the configuration changes, so it lives outside the image.
ConfigMap example:
apiVersion: v1
kind: ConfigMap
metadata: { name: orders-config }
data:
LOG_LEVEL: "info"
PAYMENT_URL: "http://payments:8080"
Secret example:
kubectl create secret generic orders-db --from-literal=DB_PASSWORD='S3cure!'
Using them in a pod:
envFrom:
- configMapRef: { name: orders-config }
env:
- name: DB_PASSWORD
valueFrom:
secretKeyRef: { name: orders-db, key: DB_PASSWORD }
They can also be mounted as files in a volume — useful for config files and certificates, and mounted files update automatically when the ConfigMap changes (environment variables only update when the pod restarts).
Important truth about Secrets:
- By default, Secrets are only base64-encoded, not encrypted — anyone who can read them can decode them.
- Protect them with:
- RBAC — limit who can
get/listsecrets. - Encryption at rest in etcd (managed clusters usually support KMS encryption).
- External secret managers — Vault, AWS Secrets Manager, Azure Key Vault via External Secrets Operator or the Secrets Store CSI driver.
- Never commit plain Secret YAML to Git — use Sealed Secrets or SOPS if you need them in GitOps repos.
- RBAC — limit who can
Tip for interviews: say "base64 is not encryption" and describe how you actually managed secrets — interviewers ask this a lot.