OpsCanary
kuberneteshelmPractitioner

Mastering Helm Hooks: Control Your Kubernetes Release Lifecycle

5 min read Official DocsAug 16, 2026Reviewed for accuracy
Share
PractitionerHands-on experience recommended

Helm hooks exist to give chart developers the ability to intervene at key moments in a release's lifecycle. This is crucial for ensuring that necessary operations are executed when they matter most, such as during 'helm install' or 'helm upgrade'. By utilizing hooks, you can automate tasks like database migrations or configuration updates, which are often needed before or after the main application is deployed.

The mechanism works by defining hooks with specific annotations like 'helm.sh/hook', which designates the resource as a hook. You can also set 'helm.sh/hook-weight' to determine the execution order of hooks, ensuring they run in a predictable sequence. For instance, a post-install job can be configured to execute after the main application is deployed. The library sorts these hooks by weight and waits for them to be 'Ready' before proceeding. If any hook fails, the entire release fails, which can be a double-edged sword. Additionally, hooks are not managed with the corresponding releases, meaning you must manually delete them if needed. This can lead to resource bloat if not handled properly.

In production, it's important to remember that hooks can block operations. For example, if you create resources in a hook, you cannot rely on 'helm uninstall' to clean them up. This can lead to leftover resources that clutter your cluster. Starting from Helm 3.2.0, hooks with the same weight are installed in the same order as non-hook resources, which can affect your deployment strategy. Always test your hooks thoroughly to avoid unexpected failures during critical deployment phases.

Key takeaways

  • Define hooks using the 'helm.sh/hook' annotation to control lifecycle events.
  • Set 'helm.sh/hook-weight' to manage the execution order of multiple hooks.
  • Use 'helm.sh/hook-delete-policy' to control when hook resources are deleted.
  • Be aware that hook failures will cause the entire release to fail.
  • Remember that hooks are not automatically cleaned up with 'helm uninstall'.

Why it matters

In production, effective use of Helm hooks can streamline deployment processes and reduce downtime. They allow for critical tasks to be automated at the right moments, ensuring smoother application updates and rollbacks.

Code examples

YAML
1apiVersion:batch/v1
2kind:Job
3metadata:
4  name: "{{ .Release.Name }}"
5  labels:
6    app.kubernetes.io/managed-by: {{.Release.Service | quote}}
7    app.kubernetes.io/instance: {{.Release.Name | quote}}
8    app.kubernetes.io/version: {{.Chart.AppVersion}}
9    helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
10  annotations:
11    "helm.sh/hook": post-install
12    "helm.sh/hook-weight": "-5"
13    "helm.sh/hook-delete-policy": hook-succeeded
14spec:
15  template:
16    metadata:
17      name: "{{ .Release.Name }}"
18      labels:
19        app.kubernetes.io/managed-by: {{.Release.Service | quote}}
20        app.kubernetes.io/instance: {{.Release.Name | quote}}
21        helm.sh/chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
22    spec:
23      restartPolicy: Never
24      containers:
25        - name: post-install-job
26          image: "alpine:3.3"
27          command: ["/bin/sleep", "{{default "10" .Values.sleepyTime}}"]
YAML
annotations:
  "helm.sh/hook": post-install,post-upgrade
YAML
annotations:
  "helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded

When NOT to use this

The official docs don't call out specific anti-patterns here. Use your judgment based on your scale and requirements.

Want the complete reference?

Read official docs

Test what you just learned

Quiz questions written from this article

Take the quiz →
Linux FoundationSponsor

Industry-standard certifications built by the people behind Linux and Kubernetes. Earn the CKA — the gold standard Kubernetes administrator cert. OpsCanary readers get 30% off year-round with code OPSCANARY3.

Get CKA certified →

Get the daily digest

One email. 5 articles. Every morning.

No spam. Unsubscribe anytime.