Job Restart and Backoff Policies
What you'll learn: How to configure when and how Kubernetes retries failed Job pods using restart policies and backoff limits.
Understanding Job Failures
When a Job's pod fails, Kubernetes needs to know: Should it restart immediately? Wait? Give up? This is where restart policies and backoff limits come in—they're your Job's failure-handling rulebook.
Think of it like a vending machine: if your snack gets stuck, does the machine try again immediately, wait a bit between attempts, or eventually stop trying? That's exactly what these policies control.
Pod Restart Policies for Jobs
Jobs support two restart policies in the pod template:
Never: If the pod fails, Kubernetes creates a new pod instead of restarting the same container. The failed pod remains for debugging.OnFailure: Kubernetes restarts the failed container within the same pod. No new pod is created.
apiVersion: batch/v1
kind: Job
metadata:
name: data-processor
spec:
template:
spec:
restartPolicy: OnFailure # or Never
containers:
- name: processor
image: myapp:1.0
Backoff Limits
The backoffLimit controls how many times Kubernetes will retry before marking the Job as failed. Default is 6.
spec:
backoffLimit: 3 # Stop after 3 failed attempts
Kubernetes uses exponential backoff (10s, 20s, 40s...) between retries, capping at 6 minutes. This prevents overwhelming your system with rapid retries.
When to Use Which
- Use
Neverwhen you need to inspect failed pods or when failures require fresh state - Use
OnFailurefor transient errors where a simple restart might work - Lower
backoffLimitfor expensive operations; increase for flaky workloads
Key Takeaway: Restart policies determine how pods retry (new pod vs container restart), while backoffLimit controls how many times Kubernetes will attempt before giving up—together they make Job failure handling predictable and controllable.