What are “Jobs” in Kubernetes and When to use them?

In this post, we will learn about Kubernetes Jobs and for what kind of tasks we can use them.

What are “Jobs” in Kubernetes?

👉 A Job creates one or more Pods and will continue to retry execution of the Pods until a specified number of them successfully terminate. 
👉 As pods successfully complete, the Job tracks the successful completions. When a specified number of successful completions is reached, the task (ie, Job) is complete. 
👉 A simple case is to create one Job object in order to reliably run one Pod to completion. The Job object will start a new Pod if the first Pod fails or is deleted.👉 You can also use a Job to run multiple Pods in parallel.

Kubernetes Job manifest
A manifest file for Job

Types of task suitable to run as a Job

1️⃣ Non-parallel Jobs

👉 Only one Pod is started, unless the Pod fails.
👉 The Job is complete as soon as its Pod terminates successfully.

2️⃣ Parallel Jobs with a fixed completion count

👉 Specify a non-zero positive value for .spec.completions.
👉 The Job represents the overall task, and is complete when there are .spec.completions successful Pods.

3️⃣ Parallel Jobs with a work queue

👉 Do not specify .spec.completions, default to .spec.parallelism.
👉 The Pods must coordinate amongst themselves or an external service to determine what each should work on. For example, a Pod might fetch a batch of up to N items from the work queue.
👉 Each Pod is independently capable of determining whether or not all its peers are done, and thus that the entire Job is done.
👉 Once at least one Pod has terminated with success and all Pods are terminated, then the Job is completed with success.

References

🔗 Kubernetes Jobs official documentation

"Knowledge Sharing Is Powerful"
Scroll to Top