Now you have learned how to run one-off or batch tasks with jobs, it is simple to extend the concept in order to run scheduled jobs. In Kubernetes, a CronJob is a controller that creates new jobs from a template on a given schedule.
Let's begin with a simple example. The following example will launch a job every minute. This job will output the current date and time and then exit:
fun-with-cron.yaml
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: fun-with-cron
spec:
schedule: "* * * * *"
jobTemplate:
spec:
template:
metadata:
labels:
cronjob: fun-with-cron
spec:
restartPolicy: OnFailure
containers:
- name: how-soon-is-now
image: alpine:3.6
command: ["/bin/date"]
Push the CronJob to Kubernetes with kubectl:
$ kubectl apply -f fun-with-cron.yaml
After...