This repo contains Dockerfile and OpenShift templates to run Crond.
Jobs may be configured to run as Kubernetes Jobs, from within a user defined docker images.
It uses ConfigMaps for jobs configuration and definition.
This is a temporary solution until CronJobs hit production
Create the ImageStream in your project and import it:
$ oc create -f imagestream.yaml
$ oc import-image crond
Give permission to create Job objects to service account cron
:
$ oc policy add-role-to-user admin -z cron
Now, let's create a cron application named cron
:
## Change "myproj" and "app" for the name of the project and image you want to execute the job in
$ oc process -f template.yaml -v NAME=cron,JOB_IMAGE_NAMESPACE=myproj,JOB_IMAGE_NAME=app | oc create -f -
Valid parameters are:
NAME
: the name of the appCRON_SCHEDULE
: Cron schedule to excute the jobCOMMAND
: Command to executeDOCKER_REGISTRY
,JOB_IMAGE_NAMESPACE
,JOB_IMAGE_NAME
andJOB_IMAGE_TAG
: Define image to use to run the jobJOBS_DIR
: Where to mount job's ConfigMap files
It will create the following objects:
- DeploymentConfig/cron: the crond itself, plus job management scritps from dir
root/
- ConfigMap/cron-config: crond configuration
- ConfigMas/cron-jobs: list of Job objects to execute
Configs for both crond and Jobs are stored in ConfigMaps
$ oc edit configmaps/cron-config
$ oc edit configmaps/cron-jobs
In order to create new jobs simply add entries to ConfigMap/cron-jobs
under key data
apiVersion: v1
kind: ConfigMap
metadata:
name: ${NAME}-jobs
data:
myjob: |-
# Here goes a Pod template
Then add an entry to execute your job myjob
in ConfigMaps/cron-config
:
# runs job `myjob` everydat at 3:05AM
5 3 * * * cron run-job myjob
After editing ConfigMaps you must re-deploy the application:
$ oc deploy cron --latest
The docker image ships with clean-jobs
script to delete old Job objects and it's Pods.
It's highly recomended to run it periodically:
*/5 * * * * cron clean-jobs