Skip to main content

CronJob

·161 words·1 min
Jack Warner
Author
Jack Warner
A little blog by me
apiVersion: batch/v1
kind: CronJob
metadata:
  name: devops
spec:
  schedule: "*/9 * * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: cron-devops
            image: nginx:latest
            command:
            - /bin/sh
            - -c
            - echo Welcome to xfusioncorp!
          restartPolicy: OnFailure

Apply the CronJob

kubectl apply -f cronjob.yaml

Verify the CronJob

kubectl get cronjob devops

Check jobs created by the CronJob

kubectl get jobs

View CronJob details

kubectl describe cronjob devops

Cron Schedule Reference
#

FieldValuesDescription
Minute0-59Minute of the hour
Hour0-23Hour of the day
Day of Month1-31Day of the month
Month1-12Month of the year
Day of Week0-6Day of the week (0 = Sunday)

Common examples:

  • */5 * * * * — Every 5 minutes
  • 0 * * * * — Every hour
  • 0 0 * * * — Daily at midnight
  • 0 0 * * 0 — Weekly on Sunday at midnight

Related notes#

  • CountdownJob — a one-shot Job (vs. this recurring CronJob)

Related