Kubernetes Simulator

intermediate · ~10 min

Migrate, then release

payments 2.0 is ready to ship, but it reads a refunds table that only exists once database migration 0042 has run. migrate.yaml is a Job that runs it.

Run the migration, wait for it to complete, and only then roll payments to ghcr.io/hackademy/payments:2.0. kubectl wait --for=condition=complete job/NAME blocks until a Job has finished, so nothing after it starts early.

kubectl wait

Blocks until an object meets a condition, then returns: --for=condition=complete for a Job, condition=available for a Deployment, condition=ready for pods. --timeout bounds the wait (30s by default) and makes it fail loudly. Scripts and release pipelines use it so one step never starts before the last one finished. Docs

Objectives

  • Migration 0042 completed
  • payments: 2 ready replicas on 2.0
  • No 2.0 pod started before the migration finished
  • Bonus: Wait with kubectl wait, not by watching

Best on a computer with a keyboard. It works on a phone, with shortcuts under the terminal.