Kubernetes Job Resource Fundamentals
What you'll learn: How to use Kubernetes Jobs to run batch tasks that execute once and complete successfully.
While Deployments and DaemonSets keep pods running continuously, Jobs are designed for tasks that need to run to completion and then stop—think data processing, batch calculations, or one-time migrations.
What Is a Job?
A Job creates one or more pods and ensures they successfully terminate. Unlike a Deployment that restarts failed pods indefinitely, a Job tracks completions and stops once the desired number of successful runs is achieved.
Think of it like hiring a contractor for a specific project: once the work is done, the engagement ends. You don't need them running forever.
Core Concepts
A Job manifest includes:
- Pod template spec: Defines the container(s) to run, just like in Deployments
- Completions: How many successful pod completions you need (default: 1)
- Parallelism: How many pods can run simultaneously
- Restart policy: Must be
OnFailureorNever(notAlways)
When you create a Job, Kubernetes:
- Creates the specified number of pods
- Monitors their completion status
- Recreates failed pods (depending on restart policy)
- Marks the Job complete when the target is reached
Completion Tracking
Kubernetes tracks each pod's exit status. A pod that exits with code 0 counts as successful. If a pod fails, the Job controller may recreate it based on your backoffLimit (default: 6 retries).
Jobs are perfect for:
- Database migrations
- Batch data processing
- Report generation
- Backup operations
Key Takeaway: Jobs are Kubernetes workload resources that run pods to completion rather than keeping them running indefinitely, making them ideal for batch processing and one-time tasks.