In Kubernetes, we usually think about Deployments and ReplicaSets for long-running apps like websites or APIs. But sometimes, you don’t want something to run forever — instead, you need it to start → do its job → finish. That’s where Kubernetes Jobs come in. ✅
🔹 What is a Job?
A Job in Kubernetes runs one or more Pods until they successfully complete.
- Once the task is done, the Pod stops.
- The Job tracks the Pods and makes sure they finish.
- If a Pod fails, the Job can retry it.
- When the required number of completions is reached, the Job is marked as complete.
If you delete the Job, Kubernetes also deletes all the Pods it created.
🔹 Why use Jobs?
Jobs are perfect when you need one-time or short-lived tasks instead of services that run forever.
âś… Use cases:
- Batch Processing → ETL jobs, log analysis, data cleanup, report generation
- Parallel Processing → breaking down big tasks like image processing or data analysis across multiple Pods
🔹 Example Job Manifest
Here’s a simple example of a Kubernetes Job that runs a container, prints "Hello Kubernetes", and then exits:
apiVersion: batch/v1
kind: Job
metadata:
name: hello-job
spec:
template:
spec:
containers:
- name: hello
image: busybox
command: ["echo", "Hello Kubernetes"]
restartPolicy: Never
backoffLimit: 2
👉 Run it:
kubectl apply -f hello-job.yaml
kubectl get jobs
kubectl get pods
kubectl logs <pod-name>
🔹 Job Lifecycle
- You create a Job.
- Kubernetes creates Pods to run it.
- Each Pod runs until it finishes.
- The Job is marked complete when success criteria are met.
- If you suspend a Job → Kubernetes deletes active Pods. Resume it → Pods start again.
🔹 Key Points to Remember
- restartPolicy must be Never or OnFailure.
- Jobs can be scaled to run multiple Pods in parallel.
- For repeating jobs on a schedule → use a CronJob instead.
âś… In short:
Kubernetes Jobs = best way to run one-time tasks reliably inside your cluster. They handle retries, failures, and cleanup automatically.
Top comments (0)