Pcornel
Browse topics
Options
Recent
Favorites
Containers · Technical reference

Jobs and CronJobs

Direct answer

Jobs run pods to completion with retries (backoffLimit); CronJobs create Jobs on a cron schedule.

When to use this

Use it for batch tasks and scheduled jobs in Kubernetes, or when a job did not run or failed.

First 30 seconds

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.

Operational verification

CronJob schedule → Job → pod runs to completion → success/fail recorded

Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
Docker / containerd / Podman / Kubernetes / OCI-compatible platforms
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

PlatformDocker / containerd / Podman / Kubernetes / OCI-compatible platforms
Scope / prerequisiteUse it for batch tasks and scheduled jobs in Kubernetes, or when a job did not run or failed.
What next?2 suggested next steps
Evidence0
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

2 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

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.

Key points

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.

Key checks
  • kubectl get cronjob,job -n <ns> — first check for this topic
  • kubectl get pods -o wide — pods, status, node, IP
  • kubectl describe pod <pod> — events and conditions
  • kubectl 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

FieldEffect
completions / parallelismHow many successful Pods are needed, and how many run at once
backoffLimit (default 6)Failed Pod retries before the Job is marked Failed
activeDeadlineSecondsHard time limit for the whole Job
ttlSecondsAfterFinishedDelete the finished Job and its Pods automatically
podFailurePolicyFail fast on specific exit codes, or ignore disruptions
restartPolicyNever (new Pod per retry) or OnFailure (restart in place)

CronJob settings

FieldEffect
schedule + timeZoneCron expression in that IANA time zone (default: controller's zone)
concurrencyPolicyAllow, Forbid (skip if previous still runs), Replace
startingDeadlineSecondsHow late a missed run may still start
successfulJobsHistoryLimit / failedJobsHistoryLimitJobs kept (default 3 and 1)
suspend: truePause 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.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

Common mistakes

  • CronJobs without concurrencyPolicy.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Terminology layer

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.

Aliases that resolve here
jobs and cronjobskubernetes cronjobkubernetes job backofflimit
Confirmation

Confirm action

Continue?