Understand jobs and cron jobs
Jobs run one-time tasks and track completion status, while cron jobs schedule recurring tasks using cron expressions, supporting non-parallel, parallel with fixed completion count, and work queue execution patterns.
A job tracks the overall progress of a task and updates its status with information
about active, succeeded, and failed pods. Deleting a job cleans up any pods it created.
Jobs are part of the Kubernetes API, which can be managed
with oc commands like other object types.
There are two possible resource types that allow creating run-once objects in OpenShift Container Platform:
- Job
-
A regular job is a run-once object that creates a task and ensures the job finishes.
There are three main types of task suitable to run as a job:
-
Non-parallel jobs:
-
A job that starts only one pod, unless the pod fails.
-
The job is complete as soon as its pod terminates successfully.
-
-
Parallel jobs with a fixed completion count:
-
a job that starts multiple pods.
-
The job represents the overall task and is complete when there is one successful pod for each value in the range
1to thecompletionsvalue.
-
-
Parallel jobs with a work queue:
-
A job with multiple parallel worker processes in a given pod.
-
OpenShift Container Platform coordinates pods to determine what each should work on or use an external queue service.
-
Each pod is independently capable of determining whether all peer pods are complete and that the entire job is done.
-
When any pod from the job terminates with success, no new pods are created.
-
When at least one pod has terminated with success and all pods are terminated, the job is successfully completed.
-
When any pod has exited with success, no other pod should be doing any work for this task or writing any output. Pods should all be in the process of exiting.
-
-
- Cron job
-
A job can be scheduled to run multiple times, using a cron job.
You can use a cron job to specify how the job runs. Cron jobs are part of the Kubernetes API, which can be managed with
occommands like other object types.Cron jobs are useful for creating periodic and recurring tasks, such as running backups or sending emails. Cron jobs can also schedule individual tasks for a specific time, such as if you want to schedule a job for a low activity period. A cron job creates a
Jobobject based on the time zone configured on the control plane node that runs the cronjob controller.A cron job creates a
Jobobject approximately once per execution time of its schedule, but there are circumstances in which it fails to create a job or two jobs might be created. Therefore, jobs must be idempotent and you must configure history limits.