Slide 1

Slide 1 text

Chris Short Red Hat DevOpsDays Columbus Kubernetes Cron Jobs: Dreams Really Do Come True

Slide 2

Slide 2 text

@ChrisShort devopsish.com 99999 Crons on the Wall 31 different daily newspapers Hundreds of cron jobs to run One RHEL 3 server running them The top of the hour was a nightmare sometimes No idea what broke when a cron failed

Slide 3

Slide 3 text

@ChrisShort devopsish.com

Slide 4

Slide 4 text

@ChrisShort devopsish.com Kubernetes Kubernetes is an open-source system for automating deployment, scaling, and management of containerized applications. https://kubernetes.io

Slide 5

Slide 5 text

Pods Pods are the smallest deployable units of computing that can be created and managed in Kubernetes. A Pod is a group of one or more containers (such as Docker containers) with shared storage/network and a specification for how to run the containers. https://kubernetes.io/docs/concepts/workloads/pods/pod/ @ChrisShort devopsish.com

Slide 6

Slide 6 text

Jobs "A job creates one or more pods and ensures that a specified number of them successfully terminate. As pods successfully complete, the job tracks the successful completions. When a specified number of successful completions is reached, the job itself is complete." https://kubernetes.io/docs/concepts/workloads/controllers /jobs-run-to-completion/ @ChrisShort devopsish.com

Slide 7

Slide 7 text

CronJob A Cron Job creates Jobs on a time-based schedule. One CronJob object is like one line of a crontab (cron table) file. It runs a job periodically on a given schedule, written in Cron format. https://kubernetes.io/docs/concepts/workloads/controllers /cron-jobs/ @ChrisShort devopsish.com

Slide 8

Slide 8 text

@ChrisShort devopsish.com

Slide 9

Slide 9 text

Use Case My newsletter, DevOps’ish, is a static site generated with Hugo and run on Netlify I can write the newsletter set to a date in the future Hugo won't build page until date Netlify provides a build hook that will trigger builds when called. Calling the build hook URL via curl is a way to implement scheduled posts with Hugo on Netlify. @ChrisShort devopsish.com

Slide 10

Slide 10 text

Let's Build a Kubernetes CronJob @ChrisShort devopsish.com (with a private registry because I'm a masochist)

Slide 11

Slide 11 text

@ChrisShort devopsish.com

Slide 12

Slide 12 text

@ChrisShort devopsish.com

Slide 13

Slide 13 text

@ChrisShort devopsish.com

Slide 14

Slide 14 text

@ChrisShort devopsish.com

Slide 15

Slide 15 text

@ChrisShort devopsish.com

Slide 16

Slide 16 text

@ChrisShort devopsish.com

Slide 17

Slide 17 text

@ChrisShort devopsish.com

Slide 18

Slide 18 text

Conclusion Built a Docker container Pushed the image to a private registry Configured Kubernetes to use the private registry Created secret to store the build hook URL Created the CronJob

Slide 19

Slide 19 text

References Everything but the secret The Children's Illustrated Guide to Kubernetes What is a Job? | Kubernetes CronJob | Kubernetes Secret | Kubernetes Kubernetes: Cron Jobs chrisshort/k8s-cron-job-demo Google Cloud Registry (GCR) with external Kubernetes

Slide 20

Slide 20 text

@ChrisShort devopsish.com