Skip to main content...
Kubernetes Core
15 min

Day 52: Jobs and CronJobs

Run-to-completion workloads

A Job runs a Pod until it successfully completes (unlike a Deployment, which keeps a Pod running forever and restarts it if it exits) — for batch work: a data migration, a one-off script, a report generation.

A CronJob creates Jobs on a schedule, using the same cron syntax from Phase 1, Day 11 — Kubernetes's answer to "run this every night at 2am" but managed and observable through kubectl instead of a server's local crontab.

A CronJob
apiVersion: batch/v1
kind: CronJob
metadata:
  name: nightly-backup
spec:
  schedule: '0 2 * * *'
  jobTemplate:
    spec:
      template:
        spec:
          containers:
            - name: backup
              image: myapp/backup:latest
          restartPolicy: OnFailure

Key terms

Job
Runs a Pod until successful completion, rather than keeping it running indefinitely.
CronJob
Creates Jobs on a cron schedule.

A Pod inside a Job exits with status 0 (success). What happens next, and how does this differ from a Deployment?

We use cookies

We use cookies to enhance your browsing experience, serve personalized content, and analyze our traffic. By clicking "Accept All", you consent to our use of cookies. Learn more

    Day 52: Jobs and CronJobs | RBTechIconX