Problem statement
Namespace batch-runs runs the ledger batch the way the team has always run it: as plain pods. nightly-rollup does its two seconds of work, exits cleanly, and the kubelet starts it again - its restart count is a tally of how many times a finished task was re-run for nothing. invoice-export failed hours ago and nothing retried it; it sits there in Failed and no one noticed. Neither pod can answer the only question that matters at six in the morning: did the batch run, and did it finish?
About this exercise
A pod is built for a process that is supposed to run forever, and its restart policy says so: the default, Always, treats exited as broken and starts the container again, whether it exited 0 or 3. Batch work is the opposite shape - it starts, it does a finite amount of work, it ends, and something has to record that it ended.
A Job is that something. It is a controller with a pod template, and what it adds is accounting. completions is how many pods must reach Succeeded before the work is done. The Job creates them, watches them, counts them in status.succeeded, and when the count is reached it writes a condition of type Complete onto itself - a terminal fact you can read hours later instead of a phase you had to be watching for. When a pod fails, backoffLimit is how many times the Job is allowed to try again before it gives up.
The pod template of a Job cannot use Always - the API rejects it, because a container the Job just watched succeed must not be restarted underneath it. Never gives every attempt its own pod; OnFailure restarts the container inside the same pod.
What the Job leaves behind is deliberate. Finished pods are not swept away: they stay in the namespace with their exit codes and their logs, which is what makes a Job auditable in the morning. They stay until you delete them, or until a ttlSecondsAfterFinished you set expires - and if you set none, nothing expires.
kubectl explain job.spec lists every field.
How this project is graded
The grader reads the live Job: the fields you declared, the succeeded count the controller wrote, the terminal condition on the Job, and every pod the Job owns - phase, restart count, exit code and log output. It also comes back after the Job has finished to check that the Job and its pods are still there to be read. The two hand-run pods are re-seeded if you remove them, and they are graded as nothing: they are the control group.
What you will build
One Job in namespace batch-runs:
name ledger-rollup completions 3 backoff limit 2 pod restart policy Never container name rollup, image busybox:1.36 the task the command nightly-rollup runs today - it prints ROLLUP SEGMENT DONE
manifest.yaml holds the two hand-run pods exactly as they are now, the rollup task's command included. Take the task from there; leave those two pods alone.
Set nothing else. No parallelism field, and no ttlSecondsAfterFinished - the finished Job and its pods have to still be readable when the grader comes back for them.
Step 1 - run the task as a Job
Declare ledger-rollup with the three completions and the retry budget above, and let it run the rollup task to the end. When it is done the Job's own status, not your manifest, reports three succeeded.
job_declares_completions_and_backoff_limit and job_runs_the_task_to_the_declared_completions should pass
Step 2 - what a finished pod does next
Three pods ran the task and every one of them exited 0. Unlike nightly-rollup, none of them may have been started again, and none of them may have disappeared.
completed_pods_stay_succeeded_and_are_not_restarted and finished_job_and_its_pods_remain_readable should pass
Step 3 - the verdict on the Job itself
The count is not the answer, it is the evidence. The Job has to carry the terminal condition that says the work completed.
job_conditions_report_complete should pass
When every test passes
You have:
- Batch work run by an object that knows work can end, instead of a pod that treats ending as a fault
- Three completions counted by the cluster, not by a person watching a terminal
- Finished pods left succeeded and un-restarted, with their exit codes and logs intact
- A Complete condition on the Job that answers "did last night's batch finish?" the next morning
You do not have yet:
- Any bound on the other outcome. A task that never succeeds retries on a schedule of its own, and one that hangs holds its slot forever. Bounding both is the next exercise.
Verify
Click Test after every step.
