Skip to main content

CronJob

·149 words·1 min
Jack Warner
Author
Jack Warner
A little blog by me
Table of Contents
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
#

Field Values Description
Minute 0-59 Minute of the hour
Hour 0-23 Hour of the day
Day of Month 1-31 Day of the month
Month 1-12 Month of the year
Day of Week 0-6 Day 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