Kubernetes Jobs and CronJobs: Batch and Scheduled Workloads

Run one-off and scheduled tasks on Kubernetes: Job completions and parallelism, retries and backoff, CronJob schedules, concurrency policy and cleanup.

Published December 2, 2026

Not everything is a long-running server. Database migrations, report generation, data imports, backups and nightly cleanups run to completion and stop. Kubernetes models these with Jobs (run to completion) and CronJobs (create Jobs on a schedule), with retries, parallelism and history built in.

The concept

A Job creates one or more pods and tracks successful completions. completions sets how many successful pods are needed; parallelism sets how many run at once; backoffLimit sets how many failures are retried before the Job is marked failed; activeDeadlineSeconds caps total runtime. Pods in Jobs use restartPolicy OnFailure or Never, never Always.

A CronJob creates a Job on a cron schedule, optionally in a specific time zone. concurrencyPolicy controls overlap (Allow, Forbid, Replace), startingDeadlineSeconds handles missed schedules, and history limits keep a few finished Jobs for inspection. ttlSecondsAfterFinished automatically deletes finished Jobs and their pods.

Key settings

FieldPurposeExample
completionsSuccessful pods required1 (default), or N for work queues
parallelismPods running at once5
backoffLimitRetries before failing3
activeDeadlineSecondsHard time limit3600
ttlSecondsAfterFinishedAuto-cleanup86400
concurrencyPolicy (CronJob)Overlap handlingForbid

Lifecycle of a scheduled run

CronJob controllerJobPod02:00 create Jobstart podexit 1 (failed)retry (backoff)exit 0Job complete
A scheduled run with one retry.

Handling overlap

concurrencyPolicyIf previous run still active
AllowStart another run in parallel
ForbidSkip this run
ReplaceCancel the old run, start a new one

Practical examples

A nightly backup CronJob

No overlap, cleanup after a day, time zone set explicitly.

apiVersion: batch/v1
kind: CronJob
metadata: { name: db-backup }
spec:
  schedule: "0 2 * * *"
  timeZone: "Asia/Kolkata"
  concurrencyPolicy: Forbid
  successfulJobsHistoryLimit: 3
  failedJobsHistoryLimit: 3
  jobTemplate:
    spec:
      backoffLimit: 2
      activeDeadlineSeconds: 3600
      ttlSecondsAfterFinished: 86400
      template:
        spec:
          restartPolicy: OnFailure
          containers:
            - name: backup
              image: example/pg-backup:1.4
              envFrom: [{ secretRef: { name: backup-creds } }]

Run a migration Job before deploying

Wait for completion in CI.

kubectl apply -f migrate-job.yaml
kubectl wait --for=condition=complete job/migrate-2-3-1 --timeout=10m
kubectl logs job/migrate-2-3-1

Trigger a CronJob manually

Useful for testing or a missed run.

kubectl create job --from=cronjob/db-backup db-backup-manual-$(date +%s)

Common mistakes

  • restartPolicy Always in a Job (invalid) or forgetting retries are counted per pod.
  • Non-idempotent jobs that cause damage when retried.
  • Allowing overlapping runs of jobs that should not run concurrently.
  • Never cleaning up finished Jobs, cluttering the cluster.

Key takeaways

  • Jobs run to completion with retries; CronJobs schedule Jobs.
  • Tune completions, parallelism, backoffLimit and deadlines.
  • Use concurrencyPolicy Forbid for exclusive tasks.
  • Make jobs idempotent and clean up with TTLs.

FAQ

What time zone do CronJobs use?

The controller's time zone (usually UTC) unless you set spec.timeZone.

Can a Job process a work queue?

Yes, with parallel workers pulling from a queue, or Indexed Jobs where each pod gets an index.

Why did my CronJob not run?

Check the schedule syntax, suspend flag, startingDeadlineSeconds and controller events with kubectl describe cronjob.

More DevOps articles