<p><strong>ATT</strong>: I dont know why, but sometimes one pod suddenly change status to Unknown, that's where the new pod starts</p>
<p>I'm using kubernetes in gcloud.</p>
<p>I built the yaml file for the cron job that I need to run:</p>
<pre><code>apiVersion: batch/v1beta1
kind: CronJob
metadata: 
  name: etl-table-feed-from-schema-vtex-to-schema-sale-all
spec:
  schedule: &quot;* * * * *&quot;
  concurrencyPolicy: &quot;Forbid&quot;
  failedJobsHistoryLimit: 3
  successfulJobsHistoryLimit: 1
  startingDeadlineSeconds: 60 # 1 min
  jobTemplate:
    spec:
      backoffLimit: 0
      #activeDeadlineSeconds: 3600 # 1 hora
      template:
        spec:
          containers:
            - name: etl-table-feed-from-schema-vtex-to-schema-sale-all
              image: (myimage)
              command: [&quot;/bin/sh&quot;, &quot;-c&quot;]
              args: (mycommands)
              env:
              - name: PYTHONUNBUFFERED
                value: &quot;1&quot;
              envFrom:
              - secretRef:
                  name: etl-secret
          restartPolicy: Never
          nodeSelector:
        #&lt;labelname&gt;:value
            etlnode: etl-hi-cpu
</code></pre>
<p>I need just one pod running at a time, just one. But sometimes, and I don't know why, and I can't reproduce, more than one pod run at a time.</p>
<p>I've already write the concurrencyPolicy as Forbid, but seems that it's not enough.</p>
<p>I run this in a preemptive pool in gcloud.</p>
<p>Two pods that ran at the same time:</p>
<p><a href="https://i.stack.imgur.com/5OTOQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5OTOQ.png" alt="enter image description here" /></a><a href="https://i.stack.imgur.com/D1nss.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/D1nss.png" alt="enter image description here" /></a></p>

Matheus Epifanio
<p>In my case the problem is that <code>concurrencyPolicy: &quot;Forbid&quot;</code> and <code>activeDeadlineSeconds</code> are not enough. My previous pod receives <code>SIGTERM</code> but keeps running for another 30sec (<code>terminationGracePeriodSeconds</code>) before it is actually killed, so I end up with two jobs running in parallel for 30 sec.</p>
<p>See this question: <a href="https://stackoverflow.com/q/57255323/5868044">Kubernetes Cron Job Terminate Pod before creation of next schedule</a>, in my case this answer provides the solution: <a href="https://stackoverflow.com/a/63721120/5868044">https://stackoverflow.com/a/63721120/5868044</a>. Two options:</p>
<ol>
<li>make the pod stop immediatelly on <code>SIGTERM</code> (e.g. with bash <code>trap 'exit' SIGTERM</code>)</li>
<li>leave a 30+ sec window between your jobs by setting a smaller <code>activeDeadlineSeconds</code> than the schedule interval.</li>
</ol>
