liveBook · Manning

Job controller

As explained in Kubernetes in Action, Second Edition

A Job controller is a Kubernetes controller that manages Job resources by creating and monitoring pods until the requested task completions are achieved or the Job fails.

A Job controller manages the pods for a Kubernetes Job: a task meant to finish rather than run indefinitely. When you create a Job, the controller creates its pods and tracks their progress toward the requested number of successful completions. If a pod fails or disappears before completing, the task can be retried in a pod. section 18.1.1 section 18.1.2 section 18.3

Run and inspect a Job

Apply a Job manifest with `kubectl apply -f job.yaml`, then run `kubectl get jobs`. A short task can move from `Running` with `0/1` completions to `Complete` with `1/1`. Use `kubectl describe job <name>` for pod counts and events, `kubectl get pods -l job-name=<name>` to find its pods, and `kubectl logs job/<name>` to inspect their output. The pod template must set `restartPolicy` to `OnFailure` or `Never`, not `Always`: the pod needs to be able to finish. section 18.1.1

Two Job fields determine how much work the controller runs:

  • `completions` sets the number of successful pod completions required. Without either field, a Job requires one. section 18.1.2
  • `parallelism` limits how many pods run at once. With `completions: 5` and `parallelism: 2`, the controller starts two pods and creates another as one finishes, until five have succeeded. section 18.1.2
Figure 18.3 Running a parallel Job with completion = 5 and parallelism = 2
figure

Follow the replacement of finished pods while the Job works toward five successful completions with at most two running at once. section 18.1.2

Failure handling depends first on the pod's restart policy. With `OnFailure`, the Kubelet restarts a failed container inside the same pod. With `Never`, the pod fails and the Job controller creates another pod, which might run on a different node. A Job that keeps failing can reach its backoff limit and become `Failed`; an `activeDeadlineSeconds` limit can also end it. section 18.1.3

The controller manages pods, not an application's work queue. Queue-processing containers must fetch their own items; a completed Job will not restart when new items arrive. For scheduled or repeated runs, a CronJob controller creates new Jobs, and the Job controller then creates their pods. section 18.1.5 section 18.2

How Kubernetes in Action, Second Edition covers it

How deep it goes
Explains pod creation, completion counts, parallelism, and failure handling through manifests and status output; does not descend into controller implementation.
Examples
Uses a five-completion, two-at-a-time Job, failed containers, kubectl status output, and a MongoDB work queue.
What it assumes
Assumes basic familiarity with pods, containers, and kubectl while explaining the controller's role through concrete Jobs.
What you can do after
Operate/configure it with Job manifests and kubectl; distinguish container restarts from replacement pods and inspect completion or failure.
How it connects
Connects Jobs and pods to restart policies, the Kubelet, work queues, and CronJobs.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Kubernetes in Action, Second Edition. The section links point to the parts of the book it draws on.