Chart Hooks and Lifecycle
You'll learn: How to execute jobs at precise moments during Helm release operations using pre-install, post-install, and pre-upgrade hooks.
What Are Chart Hooks?
Chart hooks let you intervene at specific points in a Helm release lifecycle—before or after installations, upgrades, deletions, or rollbacks. Think of them like middleware in web frameworks: they intercept the deployment flow to run tasks such as database migrations, backup jobs, or configuration validation before the main application starts.
Hooks are defined as annotations on Kubernetes resources (usually Jobs or Pods) within your chart templates.
Common Hook Types
pre-install: Runs before any resources are installedpost-install: Runs after all resources are installedpre-upgrade: Runs before an upgrade beginspost-upgrade: Runs after an upgrade completespre-delete: Runs before resources are deletedpost-delete: Runs after deletion finishes
Defining a Hook
Add the helm.sh/hook annotation to any Kubernetes resource:
apiVersion: batch/v1
kind: Job
metadata:
name: {{ .Release.Name }}-db-migration
annotations:
"helm.sh/hook": pre-upgrade
"helm.sh/hook-weight": "0"
"helm.sh/hook-delete-policy": hook-succeeded
spec:
template:
spec:
containers:
- name: migrate
image: myapp/migrator:1.0
command: ["./migrate.sh"]
restartPolicy: Never
The hook-weight controls execution order (lower runs first), and hook-delete-policy determines when Helm cleans up the hook resource.
Key Takeaway:
Chart hooks enable you to execute critical setup, migration, or cleanup tasks at controlled points in the release lifecycle using simple Kubernetes Job resources with special Helm annotations.