Kubernetes 101 : CronJobs
A CronJob is a kubernetes object that runs the kubenrnetes jobs at a specific time.
A Job is a kubernetes object that is meant for programs that do a specific task and then exit.
The schedule time format is a below:
- 10 * * * * : the job is scheduled ten minutes after each hour.
- 10 23 * * * : the job is scheduled everyday at 23:10.
- * * 10 * * : the job is scheduled on the tenth of each month.
- */20 * * * * : the job is scheduled every twenty minutes.
Cronjob Yaml file:
Below is an example of a CronJob Yaml configuration file:
We see that the schedule "10 * * * *" runs the Job every ten min after each hour, 1:10 , 2:10, 3:10, ...
The jobTemplate represents the job that runs according to the above schedule.
The "ls" command runs at the intervals specified in the schedule.
To create the CronJob, we run the below command:
<none>: no job has been scheduled yet.
We check also the CronJob pod using the below command. We notice that its status is "completed":