Opscraft
Kubernetes in depth · Lesson 7 of 11 · 3 min read

Configuration, secrets and the downward API

ConfigMaps and Secrets

envFrom:
- configMapRef: { name: orders-config }
env:
- name: DB_PASSWORD
  valueFrom: { secretKeyRef: { name: orders-db, key: password } }
volumeMounts:
- { name: config, mountPath: /etc/orders, readOnly: true }
volumes:
- name: config
  configMap: { name: orders-config }
Enlarge diagramConfigMap /Secretorders-configenvironment variablesread once at startmounted filesupdate in about a minutechange → restart podsapp must re-read them
Figure 1. Two ways to give config to a container, and how each behaves when the ConfigMap changes.
Swipe sideways to see all of it, or tap to open it full screen.
  • Environment variables are read once at container start — changes need a restart. Mounted files update automatically (eventually, ~1 minute) unless mounted with subPath, but the app must re-read them.
  • Trigger rollouts on config change by hashing config into a pod annotation (Kustomize's configMapGenerator does this automatically by adding a content hash to the ConfigMap's name).
  • immutable: true protects against accidental changes and reduces API load.
  • Secrets are base64-encoded, not encrypted. Protect them with: encryption at rest (KMS), tight RBAC (get/list on secrets is powerful — list reveals all values), avoiding env vars for highly sensitive values (they leak into crash dumps and /proc), and external secret stores — External Secrets Operator (syncs from AWS Secrets Manager/SSM into Secrets) or the Secrets Store CSI driver (mounts directly). For GitOps, encrypt secrets in Git with SOPS (Flux supports it natively) or Sealed Secrets.

Downward API

Expose pod metadata to the container: metadata.name, metadata.namespace, status.podIP, spec.nodeName, labels, and resource limits — useful for logging context and runtime tuning.