Kubernetes has added a new type of Job from version 1.5, namely the Cron Job, a scheduled task similar to Linux Cron, but with some differences. Kubernetes Cron Job timing expression uses minute instead of second as the first bit:

  Minutes Hours DayofMonth Month DayofWeek Yea
Copy the code

Supports four characters: “, – * / “,

* : matches any value. If used in Minutes, every minute

/ : indicates that the trigger starts at the start time and then occurs at fixed intervals.

For example, if “Minutes” is set to 5/20, it indicates that the first trigger is triggered at the 5th minute and the next trigger is triggered every 20 Minutes, that is, at the 25th and 45th Minutes

For example, if a task is executed every 1 minute, the Cron expression is as follows:

  */1 * * * *
Copy the code

Now write a Cronjob resource object to execute the job:

Cronjob API version batch/v2alpha1 is used before Kubernets 1.8. This function needs to be enabled when API Server is started.

Copy the code