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 diagram
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
configMapGeneratordoes this automatically by adding a content hash to the ConfigMap's name). immutable: trueprotects against accidental changes and reduces API load.- Secrets are base64-encoded, not encrypted. Protect them with: encryption at rest (KMS), tight RBAC (
get/liston secrets is powerful —listreveals 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.