Lifecycle Hooks and Tests
Running ordered actions at specific lifecycle phases with hook annotations, controlling execution order with weights, cleaning up hooks with deletion policies, and validating deployments with helm test.
Overview
Lifecycle control with hooks
Helm hooks run ordered actions before or after specific events in a release lifecycle: install, upgrade, delete and rollback. Without hooks, all resources are applied in Helm's fixed sort order, with no way to coordinate stateful operations like database migrations.
Take helm upgrade as the example. With hooks in the chart, it moves through these steps.
- Helm runs the pre-upgrade hooks, sorted by weight.
- If a pre-upgrade hook fails, the upgrade is aborted right there, and the old version keeps running.
- Otherwise Helm applies the non-hook resources, such as Deployments and Services.
- It runs the post-upgrade hooks.
- The release is marked DEPLOYED. Test hooks run later, and only when you call helm test explicitly.
> [!IMPORTANT] Hooks turn Helm's fixed apply order into a lifecycle you control: migrate first, deploy second, verify last.
Key concepts
- helm.sh/hook annotation
- Hook weight (helm.sh/hook-weight)
- Hook deletion policies
- Pre-upgrade migration pattern
- helm test
- --no-hooks flag
Interview questions
- How do you implement a safe database migration pattern using Helm hooks?
- Explain hook execution order with weights and what happens when a hook fails.
- How does helm test work and how do you write effective test hooks?
- What are the hook deletion policies and which combination should you use in production?
- How do you handle a situation where a pre-upgrade hook is hanging and blocking the upgrade?
Sign up free to read the full topic
More DevOps topics
- Kubernetes Storage
- Kubernetes the Hard Way
- Kubescape and Kubernetes Runtime Security
- Kustomization and Reconciliation
- Lease and Reservation Control Planes
- libstdc++, libc++, glibc and Symbol Versioning
- Linking Deep Dive
- Linux Cron & Task Scheduling
- Local Kubernetes Cluster Setup (minikube / kind / k3d)
- Log Aggregation
- Microservices Design
- Migration and Production Patterns
Start free on Cariara · Coding problems · System design studio