Scheduled jobs

For tasks that need to run periodically, Kubernetes has also released a CronJob type in alpha. As we might expect, this type of job uses the underlying cron formatting to specify a schedule for the task we wish to run. By default, our cluster will not have the alpha batch features enabled, but we can look at an example CronJob listing to learn how these types of workloads will work going forward. Save the following code in longtask-cron.yaml file:

apiVersion: batch/v2alpha1
kind: CronJob
metadata:
name: long-task-cron
spec:
schedule: "15 10 * * 6"
jobTemplate:
spec:
template:
spec:
containers:
- name: long-task-cron
image: docker/whalesay
command: ["cowsay", "Developers! Developers! Developers!
Saturday task
complete!"]
restartPolicy: OnFailure

As you can see, the schedule portion reflects a crontab with the following format: minute hour day-of-month month day-of-week.  In this example, 15 10 * * 6 creates a task that will run every Saturday at 10:15 am.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.12.186