<p>Is there a way to provide timeout to kubernetes CronJob?</p>

<p>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 <code>.spec.startingDeadlineSeconds</code> but this didn't help.</p>

danielinclouds
<p>Use <code>cronjob.spec.jobTemplate.spec.activeDeadlineSeconds</code>:</p>

<blockquote>
  <p>FIELDS: </p>
  
  <p>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</p>
</blockquote>

<p><a href="https://kubernetes.io/docs/concepts/workloads/controllers/jobs-run-to-completion/#job-termination-and-cleanup" rel="noreferrer">From documentation:</a></p>

<blockquote>
  <p>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.</p>
  
  <p>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.</p>
</blockquote>
