<p>If I set up a <a href="https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/" rel="nofollow noreferrer">kubernetes cronjob</a> with for example</p>

<pre><code>spec:
  schedule: "*/5 * * * *"
  concurrencyPolicy: Forbid
</code></pre>

<p>then it will create a job every 5 minutes.</p>

<p>However if the job takes e.g. 4 minutes, then it will create another job 1 minute after the previous job completed.</p>

<p>Is there a way to make it create a job every 5 minutes <em>after</em> the previous job finished?</p>

<p>You might say; just make the schedule <code>*/9 * * * *</code> to account for the 4 minutes the job takes, but the job might not be predictable like that.</p>

David S.
<p>Unfortunately there is no possibility within Kubernetes <code>CronJob</code> to specify a situation when the timer starts  (for example 5 minutes) after a job is completed. </p>

<p>A word about <code>cron</code>: </p>

<blockquote>
  <p>The software utility <strong>cron</strong> is a time-based <a href="https://en.wikipedia.org/wiki/Job_scheduler" rel="nofollow noreferrer" title="Job scheduler">job scheduler</a> in <a href="https://en.wikipedia.org/wiki/Unix-like" rel="nofollow noreferrer" title="Unix-like">Unix-like</a> computer <a href="https://en.wikipedia.org/wiki/Operating_system" rel="nofollow noreferrer" title="Operating system">operating systems</a>. Users that set up and maintain software environments use cron to schedule jobs (commands or <a href="https://en.wikipedia.org/wiki/Shell_script" rel="nofollow noreferrer" title="Shell script">shell scripts</a>) to run periodically at <strong>fixed times, dates, or intervals.</strong></p>
  
  <p>--  <em><a href="https://en.wikipedia.org/wiki/Cron" rel="nofollow noreferrer">Wikipedia.org: Cron</a></em>  </p>
</blockquote>

<p>The behavior of your <code>CronJob</code> within Kubernetes environment can be modified by:</p>

<ul>
<li>As said <code>Schedule</code> in <code>spec</code> definition

<pre class="lang-sh prettyprint-override"><code>  schedule: "*/5 * * * *"
</code></pre></li>
<li><a href="https://kubernetes.io/docs/tasks/job/automated-tasks-with-cron-jobs/#starting-deadline" rel="nofollow noreferrer">startingDeadline</a> field that is optional and it describe a deadline in seconds for starting a job. If it doesn't start in that time period it will be counted as failed. After a 100 missed schedules it will no longer be scheduled. </li>
<li><a href="https://kubernetes.io/docs/tasks/job/automated-tasks-with-cron-jobs/#concurrency-policy" rel="nofollow noreferrer">Concurrency policy</a> that will specify how concurrent executions of the same <code>Job</code> are going to be handled: 

<ul>
<li>Allow - concurrency will be allowed</li>
<li>Forbid - if previous <code>Job</code> wasn't finished the new one will be skipped </li>
<li>Replace - current <code>Job</code> will be replaced with a new one </li>
</ul></li>
<li><a href="https://kubernetes.io/docs/tasks/job/automated-tasks-with-cron-jobs/#suspend" rel="nofollow noreferrer">Suspend</a> parameter if it is set to <code>true</code>, all subsequent executions are suspended. This setting does not apply to already started executions.</li>
</ul>

<p>You could refer to official documentation: <a href="https://kubernetes.io/docs/tasks/job/automated-tasks-with-cron-jobs/" rel="nofollow noreferrer">CronJobs</a></p>

<p>As it's unknown what type of <code>Job</code> you want to run you could try to: </p>

<ul>
<li>Write a shell script in type of: </li>
</ul>

<pre class="lang-sh prettyprint-override"><code>    while true
    do
      HERE_RUN_YOUR_JOB_AND_WAIT_FOR_COMPLETION.sh
      sleep 300 # ( 5 * 60 seconds ) 
    done
</code></pre>

<ul>
<li>Create an image that mimics usage of above script and use it as pod in Kubernetes. </li>
<li>Try to get logs from this pod if it's necessary as described <a href="https://kubernetes.io/docs/concepts/cluster-administration/logging/#basic-logging-in-kubernetes" rel="nofollow noreferrer">here</a></li>
</ul>

<p>Another way would be to create a pod that could <a href="https://kubernetes.io/docs/tasks/access-application-cluster/access-cluster/#programmatic-access-to-the-api" rel="nofollow noreferrer">connect to Kubernetes API</a>.</p>

<p>Take a look on additional resources about <code>Jobs</code>:</p>

<ul>
<li><a href="https://kubernetes.io/docs/tasks/job/fine-parallel-processing-work-queue/" rel="nofollow noreferrer">Kubernetes.io: Fine parallel processing work queue</a></li>
<li><a href="https://kubernetes.io/docs/tasks/job/coarse-parallel-processing-work-queue/" rel="nofollow noreferrer">Kubernetes.io: Coarse parallel processing work queue</a></li>
</ul>

<p>Please let me know if you have any questions to that. </p>
