Interview Prep/DevOps Fundamentals/Containers & Kubernetes basics

What are ConfigMaps and Secrets in Kubernetes?

BeginnerConceptContainers & Kubernetes basics
Answer

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:
    1. RBAC — limit who can get/list secrets.
    2. Encryption at rest in etcd (managed clusters usually support KMS encryption).
    3. External secret managers — Vault, AWS Secrets Manager, Azure Key Vault via External Secrets Operator or the Secrets Store CSI driver.
    4. Never commit plain Secret YAML to Git — use Sealed Secrets or SOPS if you need them in GitOps repos.

Tip for interviews: say "base64 is not encryption" and describe how you actually managed secrets — interviewers ask this a lot.

All DevOps Fundamentals questions

More on Containers & Kubernetes basics