kubernetes-101-jobs-cronjobs
A Job creates one or more Pods and will continue to retry execution of the Pods until a specified number of them successfully terminate.
apiVersion: batch/v1
kind: Job
metadata:
name: job
spec:
template:
containers:
- name: nginx
image: nginx:latest
command: [”/bin/sh”, “-c”, “date;”]
backoffLimit: 4
As pods successfully complete, the Job tracks the successful completions. ✅
When a specified number of successful completions is reached, the task (Job) is complete. 🖐
A CronJob creates Jobs on a repeating schedule. ⏱️
apiVersion: batch/v1
kind: CronJob
metadata:
name: cronjob
spec:
schedule: “*/1 * * * *”
jobTemplate:
spec:
template:
spec:
containers:
- name: nginx
image: nginx:latest
command: [”/bin/sh”, “-c”, “date;”]
CronJobs are meant for performing regular scheduled actions such as backups, report generation, and so on.
Each of those tasks should be configured to recur indefinitely (for example: once a day / week / month).
Check out new-spike.net for other articles on Kubernetes and much more! 🚀