Thought Vector Blog

Try Taggit Free text topic tagging

Kubernetes Cron Container

Posted May 30, 2016

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

Using 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!


Undeleting Kafka Topics

Accidentally deleted a topic, but hadn’t set delete.topic.enable in your file, and need to undo the topic deletion? Just delete the topic deletion in Zookeeper! Just ssh into your...

author Stuart AxelbrookeBy Stuart Axelbrooke, who does data science and text analytics. You should follow him on Twitter