⚙️ What Are Helm Jobs and How to Use Them
When deploying applications in Kubernetes with Helm, sometimes you need to run a one-time task — like initializing a database, migrating data, or running cleanup scripts. That’s where Helm Jobs come in.
🧩 What Is a Helm Job?
A Helm Job is just a regular Kubernetes Job resource defined inside a Helm chart.
It runs once (or until success), unlike Deployments or StatefulSets that keep running.
However, what makes it special in Helm is how you control when it runs — using Helm hooks.
⚙️ Using Helm Hooks with Jobs
Helm provides lifecycle hooks such as:
pre-installpost-installpre-upgradepost-upgradepre-deletepost-delete
You can attach these hooks to a Job using annotations.
Example:
apiVersion: batch/v1
kind: Job
metadata:
name: "{{ .Release.Name }}-db-init"
annotations:
"helm.sh/hook": pre-install
"helm.sh/hook-delete-policy": before-hook-creation,hook-succeeded
spec:
template:
spec:
containers:
- name: db-init
image: myregistry/db-init:latest
command: ["sh", "-c", "python migrate.py"]
restartPolicy: Never
This Job will run before the Helm release is installed, performing your setup logic, then automatically cleaned up.
💡 Common Use Cases
- Database migrations before app deployment
- Cache warming or config generation
- Cleanup tasks on uninstall
🧭 Best Practices
- Always set restartPolicy: Never
- Use hook-delete-policy to prevent leftover Jobs
- Add resource limits to avoid stuck jobs
🚀 Summary
Helm Jobs are a powerful way to add one-time setup or cleanup logic into your Kubernetes deployments. They help automate initialization processes and make your Helm charts more production-ready — with minimal overhead.