pikachunetes:
Hello CKADers,
Create a cron job with image busybox that runs every minute and writes ‘date; echo Hello from the Kubernetes cluster’ to standard output. The cron job should be terminated if it takes more than 17 seconds to start execution after its schedule.
For the above question, do we have to add activeDeadlineSeconds=17
or startingDeadlineSeconds=17
and Why!
Thank you
Dhawan Shringi:
Based on the first comment, it should be activeDeadlineSeconds
.
pikachunetes:
@Dhawan Shringi, as in the question it is asked if it takes more than 17 seconds to start and not 17 secs to execute
Shouldn’t it be startingDeadlineSeconds
cc: @Fernando Jimenez
Dhawan Shringi:
My bad, I misread the question, it should be startingDeadlineSeconds
.
unnivkn:
The .spec.startingDeadlineSeconds
field is optional. It stands for the deadline in seconds for starting the job if it misses its scheduled time for any reason. After the deadline, the cron job does not start the job. Jobs that do not meet their deadline in this way count as failed jobs.
unnivkn:
The activeDeadlineSeconds
applies to the duration of the job, no matter how many Pods are created. Once a Job reaches activeDeadlineSeconds
, all of its running Pods are terminated and the Job status will become type: Failed
with reason: DeadlineExceeded
.
unnivkn:
So the answer is : startingDeadlineSeconds
Dhawan Shringi:
Based on the docs:
For every CronJob, the CronJob Controller checks how many schedules it missed in the duration from its last scheduled time until now. If there are more than 100 missed schedules, then it does not start the job and logs the error
It is important to note that if the startingDeadlineSeconds field is set (not nil), the controller counts how many missed jobs occurred from the value of startingDeadlineSeconds until now rather than from the last scheduled time until now.
So, it should be activeDeadlineSeconds
Dhawan Shringi:
The above post doesn’t talk much about startingDeadlineSeconds
and based on the documentation, my understanding is that the cron job controller uses the parameter startingDeadlineSeconds
to see if there where more than 100 misses in the last duration of startingDeadlineSeconds
if not, it will allow the execution of cron job.
pikachunetes:
I think the question is a little ambiguous as it talks about the termination of the cronjob itself and not the job created by it. startingDeadlineSeconds
and activeDeadlineSeconds
both can terminate the job and not the whole cronjob.
but still, the former option looks more promising.
Dhawan Shringi:
It talks about startingDeadlineSeconds
https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/#cron-job-limitations|here, however it doesn’t say anywhere that the parameter can terminate a cronjob, not in the official documentation. Maybe we’ll have to implement it to be 100 percent sure and yes, it is certainly ambiguous question.
Fernando Jimenez:
startingDeadlineSeconds
makes the most sense in combination with Currency Policy Forbid. That’s why it is by default unset.
With a Current Policy Forbid, you are telling Kubernetes that you do not want more than one job running at a time. This is important if your job takes longer and overlaps with the next time the scheduled job should start. The startingDeadlineSeconds
still allows a job to start past the schedule, if the previous job has finished. It also prevents the lockdown of more than 100 fails.
Fernando Jimenez:
Based on the original question, the actual answer should be activeDeadlineSeconds
pikachunetes:
Great explanation there!
@Fernando Jimenez, can you pls explain how does activeDeadlineSeconds
fits right in the original question. That’s still a grey area for me.
“job should be terminated if it takes more than 17 seconds to start execution after its schedule”