Cron jobs in OpenShift

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.

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *