In Kubernetes, you define the schedule for a CronJob using the schedule field in the CronJob specification. The schedule is specified in Cron format, which consists of five fields representing minute, hour, day of month, month, and day of week.
Here is an example of a CronJob definition with a schedule:
apiVersion: batch/v1
kind: CronJob
metadata:
name: example-cronjob
spec:
schedule: "0 * * * *" # This means the job will run at the start of every hour
jobTemplate:
spec:
template:
spec:
containers:
- name: example
image: your-image
args:
- /bin/sh
- -c
- "echo Hello from the CronJob!"
restartPolicy: OnFailure
In this example, the CronJob is scheduled to run at the start of every hour. You can adjust the schedule field according to your requirements.
