A workload controller designed for finite, batch-style tasks that run to completion. Unlike Deployments or DaemonSets, a Job creates Pods that are expected to terminate successfully and then stop. Synthesized from CKA Day 12 — DaemonSet, Job & CronJob Explained.
What is a Job?
A Job creates one or more Pods and ensures that a specified number of them successfully terminate. Once the required number of completions is reached, the Job is marked as Complete. If a Pod fails, the Job controller restarts it (up to the backoffLimit) until success or failure is declared.
Key Insight: Deployments manage Pods that should run forever. Jobs manage Pods that should finish and exit.
completions: 5, parallelism: 1 — run one Pod after another until 5 successes.
Parallel Workers
completions: 10, parallelism: 3 — run up to 3 Pods at a time until 10 total successes.
Work Queue (Indexed Job)
Set completionMode: Indexed so each Pod gets a unique index (0 to N-1) via the JOB_COMPLETION_INDEX environment variable. Useful for sharded or partitioned batch processing.
Job Lifecycle
Phase
Description
Pending
Job created, Pods not yet scheduled
Active
At least one Pod is running
Complete
Required number of completions reached successfully
Failed
backoffLimit exhausted or activeDeadlineSeconds exceeded
Essential Commands
Command
Purpose
kubectl get jobs
List Jobs
kubectl describe job <name>
Events, completions, and failures
kubectl logs job/<name>
Read logs from the Job’s Pod(s)
kubectl delete job <name>
Delete Job and its Pods
kubectl wait --for=condition=complete job/<name>
Block until Job finishes
Important Restrictions
restartPolicy: Always is invalid inside a Job template. The Job controller must detect termination, so the Pod must not restart automatically.
Deleting a Job does not delete completed Pods by default unless you set ttlSecondsAfterFinished. However, kubectl delete job will delete the Job object and its active Pods.
A Job is not self-healing in the Deployment sense. If the Pod completes, the Job stays complete. To run it again, you must create a new Job.
CKA Exam Relevance
Workloads & Scheduling (~15%): Create a Job from a given spec, or debug why a Job is stuck in Pending or Failed.
Troubleshooting (~30%): Check restartPolicy first. If it is Always, the Job will fail validation. Check backoffLimit and activeDeadlineSeconds for premature termination.
Exam-style hands-on tasks for this topic. Complete each task before reviewing the solution. Time yourself — CKA tasks average 5–7 minutes.
Task 1: Create a Pi-Calculation Job
You are asked to create a Job named pi-calc that calculates pi to 2000 decimal places using the command perl -Mbignum=bpi -wle 'print bpi(2000)'.
Requirements: Use the perl:5.34 image. The Job must complete successfully.
Verification:kubectl logs job/pi-calc shows a long number starting with 3.14…
Solution:
kubectl create job pi-calc --image=perl:5.34 --dry-run=client -o yaml > pi-calc.yaml# Edit the command in the manifest to: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"]# Ensure restartPolicy: OnFailurekubectl apply -f pi-calc.yaml
Task 2: Parallel Job with Completions
You are asked to create a Job named batch-worker that runs 5 total completions with a parallelism of 2.
Requirements: Use busybox image with command echo "worker done". Set completions: 5 and parallelism: 2.
Verification:kubectl get job batch-worker shows 5/5 completions.
Solution:
Task 3: Debug BackoffLimitExceeded
A Job named data-process is stuck with status BackoffLimitExceeded. Inspect the Pod logs and fix the command so the Job completes.
Requirements: Identify the failing Pod, read its logs, edit the Job manifest to use the correct command, delete the old Job, and recreate it.
Verification:kubectl get job data-process shows Completed.
Solution:
kubectl get pods -l job-name=data-processkubectl logs <failing-pod># Fix the command in the manifest (e.g., correct a typo or path)kubectl delete job data-processkubectl apply -f data-process.yaml