Tech Interview RoomStudy guides

Kubernetes

How do you manage configuration and secrets in Kubernetes?

Intermediate · 2 min read · Lesson 3 of 7 in Kubernetes

ConfigMaps

Non-sensitive configuration as key-value pairs or files.

  • As environment variables (envFrom): simple, but values are fixed at container start.
  • As mounted files: updated in place (eventually) when the ConfigMap changes, which lets applications reload (Spring Cloud Kubernetes, or a file watcher). Changes to env-var-based config need a rollout; a common trick is a checksum annotation on the pod template so a config change triggers a rolling restart (Helm does this easily).

Secrets

  • Same mechanics, but intended for sensitive data. By default they are only base64-encoded, not encrypted: enable encryption at rest in etcd (KMS provider), restrict access with RBAC, and avoid exposing them as environment variables where they can leak into crash dumps and child processes; mounted files are safer.
  • Better: keep the source of truth in an external manager (Vault, AWS Secrets Manager, GCP Secret Manager, Azure Key Vault) and sync with the External Secrets Operator or mount with the Secrets Store CSI driver, with rotation.
  • Give pods cloud permissions through workload identity (IRSA or EKS Pod Identity, GKE Workload Identity) instead of static cloud keys in secrets.

Spring Boot

spring.config.import=configtree:/etc/config/ reads mounted files as properties (file name = property name), which works well with mounted secrets.

Follow-up questions interviewers ask

Try answering each one before you open it.

How do you roll out a config change safely?

Treat configuration like code: change it in Git, review it, and let the GitOps tool apply it; trigger a rolling restart through a pod-template checksum so pods pick it up gradually with readiness checks; validate configuration at startup (@Validated @ConfigurationProperties) so a bad value fails the new pods' readiness instead of breaking traffic; and roll back by reverting the commit.