Course contentsShow
← Cloud and Infrastructure
Lesson 1547 of 2,98931. Helm Package ManagerFree lesson

Chart Hooks and Lifecycle

Implement pre-install, post-install, pre-upgrade hooks to execute jobs at specific points in the release lifecycle.

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 installed
  • post-install: Runs after all resources are installed
  • pre-upgrade: Runs before an upgrade begins
  • post-upgrade: Runs after an upgrade completes
  • pre-delete: Runs before resources are deleted
  • post-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.