Helm Hooks for Lifecycle Management
You'll learn how to control the exact timing of resource creation and job execution during chart installations and upgrades using Helm hooks.
What Are Helm Hooks?
Helm hooks let you intervene at specific points in a release's lifecycle—think of them as "event listeners" that trigger actions before or after major operations. Just like lifecycle hooks in programming frameworks, Helm hooks allow you to run special resources (often Jobs or Pods) at precise moments: before installing resources, after they're created, before deletion, and more.
Instead of deploying everything simultaneously, hooks give you orchestration power to sequence operations.
Common Hook Types
Helm provides several hook annotations you add to your resource manifests:
pre-install– Runs before any chart resources are createdpost-install– Runs after all resources are created and readypre-upgrade– Executes before an upgrade beginspost-upgrade– Fires after upgrade completespre-delete– Triggers before resources are deletedpost-delete– Runs after deletion finishes
Add the annotation "helm.sh/hook": "pre-install" to a Job's metadata to make it a hook.
Practical Use Cases
Use hooks to:
- Run database migrations before deploying your app (
pre-install,pre-upgrade) - Wait for external dependencies to be ready
- Send notifications after successful deployments (
post-install) - Clean up resources or backup data before deletion (
pre-delete) - Execute smoke tests after upgrades (
post-upgrade)
Hooks run in weight order (use "helm.sh/hook-weight" annotation) and can be configured to delete themselves automatically with "helm.sh/hook-delete-policy".
Key Takeaway: Helm hooks give you fine-grained control over resource lifecycle timing, enabling you to run initialization, migration, testing, and cleanup tasks at exactly the right moment in your deployment process.