How to write and use Kubernetes CronJobs

Tremaine Eto
cloud native: the gathering
6 min readJun 12, 2019

--

Want to perform actions on a time-based schedule within Kubernetes? Then Kubernetes CronJobs — formerly called ScheduledJobs — are the answer.

First up, can you give me the official documentation?

Sure!

What does a CronJob do?

You can create a CronJob and specify a cron expression. Based on the schedule cron expression, the CronJob will then run any command(s) you specify as well as the image you specify.

Can I have an example CronJob .yaml spec?

Sure!

Can you break that spec down?

Of course. First of all, when it comes to making your own CronJob spec, you will want to change the name and namespace fields under metadata. This will directly be the name and namespace of your CronJob resource — a.k.a. what you will find your CronJob under when you use kubectl or the Kubernetes Dashboard, if you have them installed.

--

--

Tremaine Eto
cloud native: the gathering

Senior Software Engineer @ Iterable | Previously worked at DIRECTV, AT&T, and Tinder | UCLA Computer Science alumni | Follow me for software engineering tips!