'How to prevent a Cronjob execution in Kubernetes if there is already a job running? concurrencyPolicy:Forbid stops the cron job execution altogether
I need a cron job to run every 5 minutes. If an earlier cron job is still running, another cron job should not start. I tried setting concurrency policy to Forbid, but then the cron job does not run at all.
- Job gets launched every 5 minutes as expected, but it launches even if the earlier cron job has not completed yet
spec:
concurrencyPolicy: Allow
schedule: '*/5 * * * *'
- This is supposed to solve the problem, but the cron job never gets launched with this approach
spec:
concurrencyPolicy: Forbid
schedule: '*/5 * * * *'
- Setting the startingDeadlineSeconds to 3600, or even to 10, did not make a difference.
spec:
concurrencyPolicy: Forbid
schedule: '*/5 * * * *'
startingDeadlineSeconds: 10
Could someone please help me here?
Solution 1:[1]
From kubernetes documentation
Concurrency Policy specifies how to treat concurrent executions of a job that is created by this cron job. The spec may specify only one of the following concurrency policies:
Allow (default): The cron job allows concurrently running jobs
Forbid: The cron job does not allow concurrent runs; if it is time for a new job run and the previous job run hasn’t finished yet, the cron job skips the new job run
Replace: If it is time for a new job run and the previous job run hasn’t finished yet, the cron job replaces the currently running job run with a new job run
In your case 'concurrencyPolicy: Forbid' should work. It will not allow new job to be run if the previous job is still running. The problem is not with concurrencyPolicy in your case.
It might be related to startingDeadlineSeconds. can you remove it and try
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |