Run Periodically or At Schedule Time
apiVersion: batch/v1
kind: CronJob
metadata:
name: hello
spec:
schedule: "* * * * *"
jobTemplate:
spec:
template:
spec:
containers:
- name: hello
image: busybox:1.28
imagePullPolicy: IfNotPresent
command:
- /bin/sh
- -c
- date; echo Hello from the Kubernetes cluster
restartPolicy: OnFailure
- The
.spec.schedule
field is required. The value of that field follows the Cron syntax - The
.spec.jobTemplate
defines a template for the Job that CronJob creates. - The
.spec.jobTemplate.spec.template
defines a template for actual Job
Commands
- Create a cronjob
kubectl create -f cronjob.yaml
- Check cronjob detail
kubectl get cronjob
- To delete the cronjob
kubectl delete cronjob <job-name>
⬅️ Jobs | ➡️