Interview Prep/Kubernetes/Deployments and rollouts

You must deploy a database migration that runs once before the new app version starts. How?

IntermediateScenarioDeployments and rollouts
Answer

Situation read → Each release needs a schema migration, and running it from every app pod would race.

What I'd do →

  1. Run the migration as a Job (or a Helm pre-upgrade hook) with backoffLimit and activeDeadlineSeconds
  2. Use an expand-and-contract migration so the old version still works with the new schema
  3. Gate the Deployment update on Job completion in CI (kubectl wait --for=condition=complete job/migrate --timeout=300s)
  4. Avoid init containers for migrations, since every replica would run them
  5. Keep the migration idempotent and take a backup first

Why → A Job runs to completion exactly once, and backward-compatible migrations make rollbacks safe.

Interview tip → Interviewers like hearing "expand, deploy, contract" for zero-downtime schema changes.

All Kubernetes questions Roadmap: Kubernetes core

More on Deployments and rollouts