So, you’ve got a Kubernetes cluster, and a cron task you need to run. Running it on your machine is an obviously bad idea, as is shoe horning it into another machine in your cloud fleet. Wouldn’t it be great to run this daily/hourly/whateverly task in Kubernetes?
… Yes! Yes it would be. And you can!
It took a little digging, but setting up a cron container is actually very simple:
FROM alpine:3.3 # ... do your other task related docker setup COPY mycronfile /var/spool/cron/crontabs/root CMD crond -l 2 -f
crond will run the cron daemon in the foreground, meaning the container will continue to run. As you can see, you also need to update the cron file, which should contain something like:
* * * * * echo "This is how we do it."
Then build the container, and run it on Kubernetes:
$ docker build -t mycron . $ kubectl run mycron --image=mycron
And that’s it!