Design how a microservice on Kubernetes should get its database configuration in production.

AdvancedProductionDatabase connections in apps
Answer

Short answer

Non-secret settings (host, port, database name, pool size) come from a ConfigMap; credentials come from a cloud secret manager or Vault through External Secrets (or are replaced by IAM/managed-identity auth). The pod uses workload identity, connects over TLS to a private database endpoint allowed only from the app's security group, and migrations run as a separate pre-deploy Job.

The full picture

Git (GitOps): Deployment + ConfigMap + ExternalSecret  (no secret values)
        │
Argo CD applies ──▶ ESO reads AWS Secrets Manager (IRSA) ──▶ K8s Secret
        │
Pod: env from ConfigMap + Secret ──TLS (verify-full)──▶ RDS (private subnet, SG allows only app SG)
        │
Pre-sync Job: Flyway migrate (migration user)

Details that matter

  • Separate DB users: app user (DML only) and migration user (DDL).
  • Rotation: Secrets Manager rotation + Reloader restarts pods on change.
  • Pooling: modest pool per pod, RDS Proxy/PgBouncer if many replicas.
  • Network: NetworkPolicy allows egress only to the DB CIDR/port.
  • Observability: connection count, pool wait time and DB latency on dashboards; alerts on errors.

What to say in the interview

"ConfigMap for non-secrets, External Secrets with workload identity for credentials — or IAM auth with no password at all — TLS to a private endpoint locked down by security groups and NetworkPolicy, separate app and migration users, migrations as a PreSync Job, and rotation handled in the vault with automatic pod reloads."

All Build Tools (Java, Node.js, Python, .NET) questions Roadmap: Connecting apps to databases

More on Database connections in apps