Observe Job and CronJob Completion · CKAD
Use different controllers for long-running servers and work that should finish.
Learn with progress and quizzesFirst, understand the concepts.
Job
A Job manages Pods toward completion. Failed executions can be retried, so operations that modify external data should tolerate duplicate execution.
CronJob
A CronJob creates Jobs on a schedule. This lab suspends automatic scheduling and launches one manual Job from its template.
Success criteria
Running alone does not prove a batch task succeeded. Inspect the Job’s Complete condition, logs, and failures together.
Why it matters
A finishing task should not be judged like an always-running server. Jobs track completion; CronJobs schedule creation of Jobs.
Work through the reasoning
Completion and retries
Check Pod Succeeded together with Job Complete. backoffLimit bounds failure retries; completions and parallelism distinguish the target from concurrent execution.
Scheduling and overlap
A schedule does not guarantee exactly-once processing. Review concurrencyPolicy for long-running tasks and make data handling safe against duplicates.
Learn by doing.
Use kubectl, a personal practice Kubernetes cluster, and a POSIX shell. Each lab uses its own namespace. Use example values only in Secrets. Cleanup removes the entire practice namespace.
Create a suspended CronJob and execute one Job from its template. Observe completion without scheduling repeated work.
kubectl config current-context
kubectl create namespace study-ckad-batch --dry-run=client -o yaml | kubectl apply -f -
kubectl apply -n study-ckad-batch -f - <<'YAML'
apiVersion: batch/v1
kind: CronJob
metadata:
name: report
spec:
schedule: "*/10 * * * *"
suspend: true
jobTemplate:
spec:
backoffLimit: 1
template:
spec:
restartPolicy: Never
containers:
- name: report
image: busybox:1.36
command: ["sh", "-c", "echo batch-ok; date -u"]
YAML
kubectl create job report-once --from=cronjob/report -n study-ckad-batch
kubectl wait --for=condition=Complete job/report-once -n study-ckad-batch --timeout=120s
kubectl logs job/report-once -n study-ckad-batch
kubectl get cronjob report -n study-ckad-batchHow to check your result
Expect the Complete condition and batch-ok in logs. Confirm the CronJob remains suspended. On failure, inspect the Job and Pod logs to distinguish command errors from image problems.
Clean up practice resources
Run after checking the result. Confirm these resources belong to your practice run and contain no data you need to keep.
kubectl delete namespace study-ckad-batchApply what you learned
A task runs every minute but takes three minutes. What should you review if duplicate work is harmful?
Reveal the reasoning after trying
Review overlap policy and design unique job keys or deduplication. Forbid can reduce overlap for one CronJob, but should not be described as an exactly-once processing guarantee.
Ready to check your understanding?
Which condition indicates successful Job completion?
- A Service ClusterIP
- The Job’s Complete condition
- The length of the Pod name
- Deployment replicas
Reveal the reasoning after trying
The Job’s Complete condition
Batch work aims to finish. The Complete condition and logs confirm that outcome; Running does not.