Design database migrations for a Helm-deployed app where the database is a subchart.
IntermediateScenarioHooks, Migrations & Testing
Answer
Situation read → Migrations must run once per deploy, before new code needs the new schema, and the DB must exist first.
What I'd do →
- A Job hook annotated
post-install,pre-upgrade: on install the DB is created first; on upgrade it runs before new pods roll out. - Put the SQL in a hook ConfigMap with weight
-5; the Job has weight0(onpre-upgrade, regular ConfigMaps are not yet updated). - An init container waits for the DB with
pg_isready. hook-delete-policy: before-hook-creation,hook-succeeded;backoffLimit: 1;activeDeadlineSeconds.- Idempotent, backward-compatible migrations (or a migration tool with a lock table: Flyway, Liquibase, golang-migrate).
Why → Correct hook timing plus idempotency gives repeatable, ordered schema changes.
Interview tip → Explain why pre-install fails with an in-release database.
More on Hooks, Migrations & Testing
The migration Job takes 12 minutes on prod data and the upgrade times out. What do you change?IntermediateA migration hook failed and the Job pod was deleted, so you cannot see why. How do you fix the chart?BeginnerYou want a backup before every production upgrade. How do you do it with Helm?IntermediateA `post-install` hook seeds demo data; it ran again on every upgrade and duplicated rows. Why?IntermediateHow do you clean up external resources (DNS records, S3 buckets) when a release is uninstalled?AdvancedWhat would you put in `helm test` for a 3-tier app?Intermediate