Jobs and CronJobs¶
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 task (ie, Job) is complete. Deleting a Job will clean up the Pods it created.
CronJobs
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.
CronJob schedules use the time zone of the kube-controller-manager, which is usually UTC. Set spec.timeZone (for example America/Chicago) to schedule in a specific time zone. Use successfulJobsHistoryLimit and failedJobsHistoryLimit to control how many finished Jobs are kept, and concurrencyPolicy to decide whether runs may overlap.
Resources¶
References¶
It computes π to 2000 places and prints it out
apiVersion: batch/v1
kind: Job
metadata:
name: pi
spec:
template:
spec:
containers:
- name: pi
image: perl
command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"]
restartPolicy: Never
backoffLimit: 4
Running in parallel
apiVersion: batch/v1
kind: Job
metadata:
name: pi
spec:
parallelism: 2
completions: 3
template:
spec:
containers:
- name: pi
image: perl
command: ["perl", "-Mbignum=bpi", "-wle", "print bpi(2000)"]
restartPolicy: Never
backoffLimit: 4
apiVersion: batch/v1
kind: CronJob
metadata:
name: hello
spec:
schedule: "*/1 * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: hello
image: busybox
args:
- /bin/sh
- -c
- date; echo Hello from the Kubernetes cluster
restartPolicy: OnFailure
Gets Jobs
Gets Job Description Gets Pods and logs from the Job Deletes Job Gets CronJob Describes CronJob Runs the CronJob now, without waiting for the schedule Deletes CronJobGets Jobs
Gets Job Description Gets Pods and logs from the Job Deletes Job Gets CronJob Describes CronJob Runs the CronJob now, without waiting for the schedule Deletes CronJobActivities¶
| Lab | Description |
|---|---|
| Lab 8 - Cron Jobs | Run a periodic task with a CronJob |