CronJobs In OpenShift
CronJobs
A CronJob is a way to schedule a job by running a Pod at a certain interval. The CronJob Pods can consume ConfigMaps as environment variables, command-line arguments, or as configuration files in a volume.
A CronJob allows you to run a container with a command line to execute the tasks based on the CRON syntax. Note: OpenShift runs as UTC with no timezones so scheduling your jobs should be set in UTC.
kind: CronJob
apiVersion: batch/v1
metadata:
name: sample-cron
spec:
schedule: 0 */2 * * *
concurrencyPolicy: Forbid
suspend: false
jobTemplate:
spec:
template:
spec:
containers:
- name: sample-cron
image: 'registry.access.redhat.com/ubi9/ubi:latest'
args:
- /bin/sh
- '-c'
- >-
curl
https://config.me/ip
restartPolicy: OnFailure
successfulJobsHistoryLimit: 3
failedJobsHistoryLimit: 1
Configuration
You can tweak the following
schedule: 0 */2 * * *Should follow the CRON format as defined here.concurrencyPolicy: ForbidYou can set this toAllowbut generally you don't want to have two jobs of the CRON running at once.suspend: falseThis can be set totrueto disable the CronJob from running.image: 'registry.access.redhat.com/ubi9/ubi:latestwith your custom code container, you can use the ubi image to run Linux commands like curl to trigger CRON frameworks in like Drupal or Laravel.args:this the command you wish to run in the container, an example would bemanage.py customjob