Kubernetes ConfigMaps and Secrets: Configuration Done Right

Manage app configuration in Kubernetes: ConfigMaps vs Secrets, env vars vs mounted files, updates and reloads, encryption at rest and external secret manager...

Published December 1, 2026

Twelve-factor apps keep configuration out of the image so the same build runs in every environment. Kubernetes provides two objects for this: ConfigMaps for non-sensitive settings and Secrets for sensitive values like passwords and API keys. How you inject them, and how you protect Secrets, matters more than the YAML syntax.

The concept

Both objects hold key-value data and can be consumed as environment variables or mounted as files in a volume. Environment variables are simple but fixed at container start; changes require a restart. Mounted files update automatically (with a short delay) when the object changes, so apps that watch files can reload configuration without restarts. Values mounted via subPath do not update.

Secrets are base64-encoded, not encrypted, in their manifests. Real protection comes from enabling encryption at rest for etcd, restricting access with RBAC, avoiding committing Secret manifests to git, and often using an external secret manager (cloud secret managers, HashiCorp Vault) synchronised into the cluster by tools like External Secrets Operator, or encrypted-in-git approaches like Sealed Secrets or SOPS.

ConfigMap vs Secret

ConfigMapSecret
PurposeNon-sensitive configPasswords, tokens, keys, certs
EncodingPlain textbase64 (not encryption!)
ProtectionNormal RBACTight RBAC + encryption at rest
Size limit~1 MiB~1 MiB
In gitYesOnly encrypted (SOPS/Sealed Secrets) or via external manager

Ways to consume them

InjectionUpdates live?Use when
env / envFromNo (restart needed)Simple settings read at startup
Volume mount (files)Yes, after a short delayConfig files, certs, reloadable settings
subPath mountNoPlacing one file into an existing directory

External secret management

readcreate/updatemountCloud secret manager / Vaultsource of truthExternal Secrets OperatorsyncKubernetes Secretin clusterPodenv or file
Secrets live in a dedicated manager and sync into the cluster.

Practical examples

Create from literals and files

Avoid typing secrets into shell history in real environments.

kubectl create configmap app-config --from-literal=LOG_LEVEL=info --from-file=app.yaml
kubectl create secret generic db-creds --from-literal=username=app --from-file=password=./db-pass.txt

Consume both in a pod

Env vars for simple values, files for config.

containers:
  - name: api
    image: example/api:2.3.0
    envFrom: [{ configMapRef: { name: app-config } }]
    env:
      - name: DB_PASSWORD
        valueFrom: { secretKeyRef: { name: db-creds, key: password } }
    volumeMounts: [{ name: config, mountPath: /etc/api, readOnly: true }]
volumes:
  - name: config
    configMap: { name: app-config }

Restart pods after env changes

A rollout restart picks up new env values.

kubectl rollout restart deploy/api

Common mistakes

  • Treating base64 as encryption and committing Secret YAML to git.
  • Granting broad get/list on Secrets to many service accounts.
  • Expecting env var values to change without restarting pods.
  • Baking environment-specific config into container images.

Key takeaways

  • ConfigMaps for settings, Secrets for sensitive values.
  • Env vars need restarts; mounted files update live.
  • Secrets need encryption at rest and strict RBAC.
  • Prefer external secret managers or encrypted-in-git workflows.

FAQ

How do I auto-restart pods when config changes?

Add a checksum of the config as a pod template annotation (common in Helm charts) or use a reloader controller.

Should I use immutable ConfigMaps?

Marking ConfigMaps and Secrets immutable protects against accidental changes and reduces API server load; create a new one for each change.

Are Secrets visible to anyone on the node?

Users with access to the node or to pods that mount them can read them, which is why RBAC and node security matter.

More DevOps articles