Cron Job with timeout

3/30/2019

Is there a way to provide timeout to kubernetes CronJob?

I need to schedule a task that runs according to Cron schedule but I need to limit execution of this task to only 20 seconds. If the task runs longer than 20 seconds than it should be terminated. I tried using .spec.startingDeadlineSeconds but this didn't help.

-- danielinclouds
kubernetes

1 Answer

3/30/2019

Use cronjob.spec.jobTemplate.spec.activeDeadlineSeconds:

FIELDS:

activeDeadlineSeconds Specifies the duration in seconds relative to the startTime that the job may be active before the system tries to terminate it; value must be positive integer

From documentation:

Another way to terminate a Job is by setting an active deadline. Do this by setting the .spec.activeDeadlineSeconds field of the Job to a number of seconds.

The activeDeadlineSeconds applies to the duration of the job, no matter how many Pods are created. Once a Job reaches activeDeadlineSeconds, all of its Pods are terminated and the Job status will become type: Failed with reason: DeadlineExceeded.

-- almalki
Source: StackOverflow