How do you do database schema migrations in Kubernetes deployments safely?
IntermediateProductionRelease Engineering and Progressive Delivery
Answer
Run the migration as a one-off Kubernetes Job or Helm pre-upgrade hook using the same image as the app, with backoffLimit small and a timeout, before the new pods roll out. Use the migration tool's locking (Flyway, Liquibase and Alembic use a lock table), so concurrent runs are safe. Do not run migrations in the app's startup path when you have many replicas. Keep migrations backward compatible so a failed rollout can roll back code alone.
More on Release Engineering and Progressive Delivery
How do you do zero-downtime deployments on Kubernetes?IntermediateHow do you implement a canary release with Argo Rollouts and automated analysis?AdvancedHow do you roll back safely when a deploy includes a database migration?AdvancedHow do you design an automated rollback trigger?AdvancedHow do you handle hotfixes in a trunk-based flow?IntermediateHow do you version and release libraries versus services?Intermediate