Schedule cron job to never happen? Schedule cron job to never happen? kubernetes kubernetes

Schedule cron job to never happen?


@reboot doesn't guarantee that the job will never be run. It will actually be run always when your system is booted/rebooted and it may happen. It will be also run each time when cron daemon is restarted so you need to rely on that "typically it should not happen" on your system...

There are far more certain ways to ensure that a CronJob will never be run:

  1. On Kubernetes level by suspending a job by setting its .spec.suspend field to true

You can easily set it using patch:

kubectl patch cronjobs <job-name> -p '{"spec" : {"suspend" : true }}'
  1. On Cron level. Use a trick based on fact that crontab syntax is not strictly validated and set a date that you can be sure will never happen like 31th of February. Cron will accept that as it doesn't check day of the month in relation to value set in a month field. It just requires that you put valid numbers in both fields (1-31 and 1-12 respectively). You can set it to something like:

* * 31 2 *

which for Cron is perfectly valid value but we know that such a date is impossible and it will never happen.


kind: CronJobspec:    suspend: true


Why do you need this to be a CronJob in the first place? If you never want it to run, you could specify a simple Job: https://kubernetes.io/docs/concepts/workloads/controllers/job/