Interview Prep/Helm/Hooks, Migrations & Testing

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 →

  1. A Job hook annotated post-install,pre-upgrade: on install the DB is created first; on upgrade it runs before new pods roll out.
  2. Put the SQL in a hook ConfigMap with weight -5; the Job has weight 0 (on pre-upgrade, regular ConfigMaps are not yet updated).
  3. An init container waits for the DB with pg_isready.
  4. hook-delete-policy: before-hook-creation,hook-succeeded; backoffLimit: 1; activeDeadlineSeconds.
  5. 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.

All Helm questions Roadmap: Helm

More on Hooks, Migrations & Testing