A CronJob creates a Job on a schedule.
Job cleanup-29096885at 09:05
Job cleanup-29096890at 09:10
Job cleanup-29096895at 09:15
text
learner@shallows:~$ kubectl create cronjob cleanup --image=busybox --schedule="*/5 * * * *" -- sh -c 'echo cleaning'
cronjob.batch/cleanup created
learner@shallows:~$ kubectl get cronjobs
NAME SCHEDULE TIMEZONE SUSPEND ACTIVE LAST SCHEDULE AGE
cleanup */5 * * * * <none> False 0 <none> 4scj is the short name.
The schedule
*/5minute*hour*day of month*month*day of week
| Schedule | Means |
|---|---|
*/5 * * * * | Every 5 minutes |
0 * * * * | On the hour |
30 2 * * * | Every day at 02:30 |
0 9 * * 1 | Mondays at 09:00 |
Run it now
Do not wait for the clock. Create a Job from the CronJob's template:
text
learner@shallows:~$ kubectl create job cleanup-now --from=cronjob/cleanup
job.batch/cleanup-now createdThe switches
| Field | Meaning |
|---|---|
suspend: true | Stop creating Jobs; running ones finish |
concurrencyPolicy | Allow (default), Forbid (skip if one is still running), Replace (kill it and start anew) |
successfulJobsHistoryLimit | Finished Jobs to keep (default 3) |
failedJobsHistoryLimit | Failed Jobs to keep (default 1) |
Change one in place:
text
learner@shallows:~$ kubectl patch cronjob cleanup -p '{"spec":{"suspend":true}}'
cronjob.batch/cleanup patched