Summary - Job and CronJob
- Docker & Kubernetes course
- Advanced
- Lesson 30/70
- 5 min
Combine Job and CronJob YAML to write scheduled tasks.
Summary: Job and CronJob
In this group:
- A Job runs a task to completion;
restartPolicyis Never/OnFailure, andbackoffLimitis the retry limit. activeDeadlineSecondsmanages the time,ttlSecondsAfterFinishedthe cleanup;kubectl wait --for=condition=completewaits.completions/parallelismgive multiple and parallel runs;Indexedmode gives an index per part.- A CronJob creates Jobs on a schedule: cron format,
timeZone,jobTemplate. concurrencyPolicymanages overlap and history limits manage old Jobs;create job --from=cronjob/triggers by hand.
kubectl create job goc --from=cronjob/gece-yedek
kubectl wait --for=condition=complete job/goc --timeout=300sPractice A bounded, self-cleaning Job
Write a Job's spec section (starting with spec:): backoffLimit: 2, activeDeadlineSeconds: 600, ttlSecondsAfterFinished: 3600; restartPolicy: OnFailure in the template; container named rapor, image api:1.0.
Starter code
# buraya yazSample solution
spec:
backoffLimit: 2
activeDeadlineSeconds: 600
ttlSecondsAfterFinished: 3600
template:
spec:
restartPolicy: OnFailure
containers:
- name: rapor
image: api:1.0Expected output
job.batch/rapor created
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 What happens if you write restartPolicy: Always in a Job pod template?
- The Job behaves like a Deployment
- It is ignored
- The API server rejects it Correct answer
- The Job never ends
Explanation: Only Never and OnFailure are valid in Jobs.
2 Give the schedule's time zone.
spec:
schedule: "0 3 * * *"
____: "Europe/Istanbul"
spec:
schedule: "0 3 * * *"
timeZone: "Europe/Istanbul"
Explanation: timeZone takes an IANA time zone name.
3 Match.
| Term | Meaning |
|---|---|
Job |
Once, to completion |
CronJob |
On a schedule |
backoffLimit |
Retries |
suspend |
Pause temporarily |