9

I have scheduled the K8s cron to run every 30 mins.

If the current job is still running and the next cron schedule has reached it shouldn't create a new job but rather wait for the next schedule.

And repeat the same process if the previous job is still in Running state.

k_vishwanath
  • 1,326
  • 2
  • 20
  • 28
  • Possible duplicate of [How to prevent a Cronjob execution in Kubernetes if there is already a job running](https://stackoverflow.com/questions/52614715/how-to-prevent-a-cronjob-execution-in-kubernetes-if-there-is-already-a-job-runni) – Praveen Sripati Oct 08 '18 at 00:55

2 Answers2

27

set the following property to Forbid in CronJob yaml

.spec.concurrencyPolicy

https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/#concurrency-policy

rlandster
  • 7,294
  • 14
  • 58
  • 96
k_vishwanath
  • 1,326
  • 2
  • 20
  • 28
8

spec.concurrencyPolicy: Forbid will hold off starting a second job if there is still an old one running. However that job will be queued to start immediately after the old job finishes.

To skip running a new job entirely and instead wait until the next scheduled time, set .spec.startingDeadlineSeconds to be smaller than the cronjob interval (but larger than the max expected startup time of the job).

If you're running a job every 30 minutes and know the job will never take more than one minute to start, set .spec.startingDeadlineSeconds: 60

Allen Luce
  • 7,859
  • 3
  • 40
  • 53