Reputation: 6105
If I set up a kubernetes cronjob with for example
spec:
schedule: "*/5 * * * *"
concurrencyPolicy: Forbid
then it will create a job every 5 minutes.
However if the job takes e.g. 4 minutes, then it will create another job 1 minute after the previous job completed.
Is there a way to make it create a job every 5 minutes after the previous job finished?
You might say; just make the schedule */9 * * * *
to account for the 4 minutes the job takes, but the job might not be predictable like that.
Upvotes: 0
Views: 460
Reputation: 9877
Unfortunately there is no possibility within Kubernetes CronJob
to specify a situation when the timer starts (for example 5 minutes) after a job is completed.
A word about cron
:
The software utility cron is a time-based job scheduler in Unix-like computer operating systems. Users that set up and maintain software environments use cron to schedule jobs (commands or shell scripts) to run periodically at fixed times, dates, or intervals.
The behavior of your CronJob
within Kubernetes environment can be modified by:
Schedule
in spec
definition
schedule: "*/5 * * * *"
Job
are going to be handled:
Job
wasn't finished the new one will be skipped Job
will be replaced with a new one true
, all subsequent executions are suspended. This setting does not apply to already started executions.You could refer to official documentation: CronJobs
As it's unknown what type of Job
you want to run you could try to:
while true
do
HERE_RUN_YOUR_JOB_AND_WAIT_FOR_COMPLETION.sh
sleep 300 # ( 5 * 60 seconds )
done
Another way would be to create a pod that could connect to Kubernetes API.
Take a look on additional resources about Jobs
:
Please let me know if you have any questions to that.
Upvotes: 1