If you need to periodically run some job in OpenShift you have several options. The most obvious one is to use builtin kubernetes Cron Jobs https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/. You need to set time interval, command which will be run and image which will be used for creating container. This method has one huge disadvantage especially when you are running a lot of small jobs – container is created with each run thus you are creating a lot of garbage which need to be clean up.
Your next option is to run a Pod with traditional cron daemon and schedule all jobs inside. This pod runs for all the time and commands are executed in the same container. This is nicer but it is an alchemy to make crond run as an unprivileged user and I would call it “dirty hack” (https://lists.openshift.redhat.com/openshift-archives/users/2016-February/msg00420.html).
So I was searching for more modern crond alternative and I’ve found go-crond (https://github.com/webdevops/go-crond). And I love it! It is a drop-in replacement for classic crond (uses same configuration syntax and paths) but with more options and modern features (log to stdout, run as non-root, configurable paths, written in Go).
If you are going to run periodic jobs in your Pods, give it a try.
2 thoughts on “Cron jobs in OpenShift”
Thanks on pointing out these alternatives.
Luckily with Kubernetes 3.6 you can set “successfulJobsHistoryLimit” and “failedJobsHistoryLimit” in the spec of a Cron Job to automatically clean up the jobs.
So far I could not find this option in the OpenShift 3.6/3.7 documentation. But it turns out that it also works in OpenShift 3.6!
So just set
and the cleanup happens automagically.
Hi @DANMAN, & @Lars Berning,
Do you have template for this container to deploy into OpenShift? If so could you please provide me?