Jobs and CronJobs
Jobs, a.k.a. batch jobs, are stable resources in the batch/v1
API group. They are useful when you need to run a specific number of a particular Pod, and you need to guarantee that they’ll all successfully complete.
A couple of subtleties worth noting:
- Jobs don’t have the concept of the desired state.
- Pods that are part of a Job are short-lived.
These two concepts separate Jobs from other objects like Deployments, DaemonSets, and StatefulSets. Whereas those objects keep a specified number of a certain Pods running indefinitely, Jobs manage a specified number of a certain Pod and make sure they complete and exit successfully.
The Job object implements the usual controller and watch loop. If a Pod that the Job object spawns fails, the Job will create another in its place. Once all the Pods managed by a Job complete, the Job itself completes.
Use cases include typical batch-type workloads.
Interestingly, Jobs can be useful even if you only need to run a single Pod through to completion. Basically, anytime you need to run one or more short-lived Pods, and you need to guarantee they complete successfully, the Job object is your friend!
CronJobs are just Jobs that run against a time-based schedule.
Get hands-on with 1200+ tech skills courses.