Lab 8 Solution - Cron Jobs¶
xwing-cronjob.yaml
apiVersion: batch/v1
kind: CronJob
metadata:
name: xwing-cronjob
spec:
schedule: "*/2 * * * *"
successfulJobsHistoryLimit: 3
jobTemplate:
spec:
template:
spec:
restartPolicy: OnFailure
containers:
- name: xwing-status
image: registry.access.redhat.com/ubi9/ubi-minimal
command: ["/bin/sh", "-c"]
args: ['date; echo "X-Wing fleet status: all systems go"']
oc apply -f xwing-cronjob.yaml
oc create job xwing-manual --from=cronjob/xwing-cronjob
oc wait --for=condition=Complete job/xwing-manual --timeout=60s
oc logs job/xwing-manual
Notes¶
- Time zones: schedules use the kube-controller-manager's time zone, usually UTC. Set
spec.timeZone(for exampletimeZone: America/New_York) to schedule in a specific zone. - Missed runs: set
startingDeadlineSecondsto control whether a run that was missed (for example, because the cluster was down) still starts late. - Overlapping runs:
concurrencyPolicy: Forbidskips a run if the previous one is still going.Replacecancels the old one. - Use crontab.guru to check cron expressions.