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
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
