Use it for batch tasks and scheduled jobs in Kubernetes, or when a job did not run or failed.
Jobs and CronJobs
Jobs run pods to completion with retries (backoffLimit); CronJobs create Jobs on a cron schedule.
1. kubectl get cronjob,job -n <ns> — last schedule and status.
2. kubectl describe job <j> — failures.
3. Logs of job pods.
4. Schedule and timeZone.
5. Trigger once: kubectl create job --from=cronjob/<cj> test.
CronJob schedule → Job → pod runs to completion → success/fail recorded
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 How to verify Verify boundary
Confirm the latest Job completed and check its logs. For CronJobs, confirm LAST SCHEDULE is recent and the time zone is correct. Test with kubectl create job --from=cronjob/<name> manual-test.
Step 2 Common failures Narrow the fault
restartPolicy Always is not allowed in a Job. A missed schedule while the controller was down may be skipped if startingDeadlineSeconds is short. Old Jobs pile up without ttlSecondsAfterFinished or history limits.
Check concurrencyPolicy, startingDeadlineSeconds and history limits. Failed pods keep logs only while retained. The CronJob schedule uses the controller's time zone unless timeZone is set.
kubectl get cronjob,job -n <ns>— first check for this topickubectl get pods -o wide— pods, status, node, IPkubectl describe pod <pod>— events and conditionskubectl logs <pod> [-c <c>] [--previous]— container logs (incl. previous crash)kubectl get events --sort-by=.lastTimestamp— recent cluster events
ReferenceWhat it is1 section · depth on demand
How it works
The Job controller creates Pods and counts successful completions; failed Pods are retried with backoff. The CronJob controller creates a Job at each schedule time and keeps a limited history of successful and failed Jobs.
ReferenceImportant terms & boundaries3 sections · depth on demand
Example
apiVersion: batch/v1
kind: CronJob
metadata: { name: db-backup }
spec:
schedule: "30 2 * * *"
timeZone: "Europe/Copenhagen"
concurrencyPolicy: Forbid
jobTemplate:
spec:
backoffLimit: 2
activeDeadlineSeconds: 3600
template:
spec:
restartPolicy: OnFailure
containers: [{ name: backup, image: backup:1.2 }]
Documented example, not captured output. kubectl get cronjob,job, kubectl create job --from=cronjob/db-backup manual-1 runs it now.
In depth
Job settings that decide success and failure
| Field | Effect |
|---|---|
completions / parallelism | How many successful Pods are needed, and how many run at once |
backoffLimit (default 6) | Failed Pod retries before the Job is marked Failed |
activeDeadlineSeconds | Hard time limit for the whole Job |
ttlSecondsAfterFinished | Delete the finished Job and its Pods automatically |
podFailurePolicy | Fail fast on specific exit codes, or ignore disruptions |
restartPolicy | Never (new Pod per retry) or OnFailure (restart in place) |
CronJob settings
| Field | Effect |
|---|---|
schedule + timeZone | Cron expression in that IANA time zone (default: controller's zone) |
concurrencyPolicy | Allow, Forbid (skip if previous still runs), Replace |
startingDeadlineSeconds | How late a missed run may still start |
successfulJobsHistoryLimit / failedJobsHistoryLimit | Jobs kept (default 3 and 1) |
suspend: true | Pause scheduling without deleting |
If more than 100 schedules are missed (for example the controller was down), the CronJob stops scheduling and logs an error; a startingDeadlineSeconds value limits how far back it counts.
Worked check — did last night's backup run?
kubectl get cronjob db-backup # LAST SCHEDULE, ACTIVE
kubectl get jobs -l job-name --sort-by=.status.startTime | tail -3
kubectl logs job/db-backup-29012345
kubectl create job db-backup-manual --from=cronjob/db-backup # run once now
A Job that completed only proves the container exited 0; verify the backup file itself as part of the job or in a separate check.
Common mistakes
- CronJobs without
concurrencyPolicy.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.