kubernetes
Cron Job

Cron Job

Concept and Usage of CronJob

CronJob will create jobs on a time-based schedule. It is useful when you want to run a job at a specific time or at regular intervals.

You can use this tool crontab.guru (opens in a new tab) to generate the cron expression.

FieldAllowed Values
minute0-59
hour0-23
day-of-month1-31
month1-12
day-of-week0-6 (0 is Sunday)
cronjob.yaml
apiVersion: batch/v1
kind: CronJob
metadata:
  name: backup-cron-job
spec:
  # minute, hour, day-of-month, month, day-of-week
  schedule: "0 0 1 * *" # At 00:00 on day-of-month 1
  jobTemplate:
    spec: # Job spec
      completions: 3 # run 3 pods
      parallelism: 2 # parallel run 2 pods at a time
      template: # pod template
        spec:
          containers:
            - name: backup
              image: busybox
              command: ["echo", "Backup operation"]
          restartPolicy: Never
kubectl get cronjob