Pro ยท Lesson 7 of 12

Jobs and CronJobs

A Job runs until it succeeds or hits its limit. A CronJob creates Jobs on a schedule.

Sign in to save your place.

Picture it this way

A Job is a boat you send once, with a note that says how many times it may try. A CronJob is the clock that sends that boat every night.

Jobs finish

A Job's Pod should use restartPolicy of Never or OnFailure. Always is for long-running Pods, and the API rejects it on a Job.

completions is how many successes you want. parallelism is how many Pods may run at once. backoffLimit is how many failures you tolerate. A Job that ignores a failed container will look green while the work did not happen. Read the Pod status, not only the Job's first line.

Field Question it answers
completions How many successful Pods count as done?
parallelism How many may run together?
backoffLimit How many retries before the Job fails?

CronJobs and clocks

A CronJob stores a schedule in cron format and a Job template. concurrencyPolicy is Allow, Forbid, or Replace. Forbid is the one you want when a slow run must not overlap the next night. Replace kills the previous run.

The timeZone field exists on the CronJob API. Confirm it on the cluster version you use before you depend on it. Without it, the schedule is evaluated in the controller's timezone, which you should not guess.

startingDeadlineSeconds decides how late a missed start can still run. Leave it unset only if you understand that a paused controller can later fire a burst of missed jobs.

Nightly work

  1. CronJob
  2. Job
  3. Pod

Step 1 of 3The CronJob does not do the work. It creates a Job.

Lab: one Job that prints and exits

Apply it, wait, and read the logs. Then look at the Job status. Delete the Job when you are done so it does not sit in the namespace.

kubectl apply -f - <<'EOF'
apiVersion: batch/v1
kind: Job
metadata:
  name: once
spec:
  backoffLimit: 2
  template:
    spec:
      restartPolicy: Never
      containers:
      - name: work
        image: busybox:1.36
        command: ["sh", "-c", "echo done && exit 0"]
EOF
kubectl wait --for=condition=complete job/once --timeout=60s
kubectl logs job/once

Concept summary

Knowledge check

Which restartPolicy is valid on a Job Pod?

A nightly job sometimes takes 26 hours. Which concurrencyPolicy avoids two copies?

Who creates the Pod for a CronJob?

Official sources

Checked against the linked documentation in October 2026. A later release can move a flag, a price, or a supported pair. Use the page for the version you installed.