A Cron Job is a job that runs on a given schedule, written in Cron format. It creates job objects periodically based on the defined schedule .
There are two primary
use cases:
Run jobs once at a specified point in time
Repeatedly at a specified point in time
Here is the job specification:
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: hello
spec:
schedule: "*/1 * * * *"
jobTemplate:
spec:
template:
metadata:
labels:
app: hello-cronpod
spec:
containers:
- name: hello
image: busybox
args:
- /bin/sh
- -c
- date; echo Hello World!
restartPolicy: OnFailure
N.B: This job prints the current timestamp and the message “Hello World” every minute.
$ kubectl create -f cronjob.yaml
-Watch the status of the job as shown:
$ kubectl get -w cronjobs
$ kubectl get -w pods -l app=hello-cronpod
$ kubectl logs POD_NAME
N.B : You should see “Hello World!” in the logs
$ kubectl delete -f cronjob.yaml
https://kubernetes.io/docs/tasks/job/automated-tasks-with-cron-jobs/