<p>I created a k8s CronJob with the following schedule (run every minute):</p>
<p><code>schedule: &quot;*/1 * * * *&quot;</code></p>
<p>I see my CronJob created:</p>
<pre><code>NAMESPACE     NAME                   READY   STATUS    RESTARTS   AGE
job-staging   job-1593017820-tt2sn   2/3     Running   0          10m
</code></pre>
<p>My job simply does a Printf to the log, one time, then exits.</p>
<p>When I do a <code>kubernetes get cronjob</code> I see:</p>
<pre><code>NAMESPACE     NAME                   READY   STATUS    RESTARTS   AGE
job-staging   job   */1 * * * *      False   1         19m        19m
</code></pre>
<p>When I look at the logs, it looks like it only ran once, which was the first run. Do I need to prevent my program from exiting?</p>
<p>I assumed k8s would restart my program, but maybe that's a wrong assumption.</p>

L P
<p>Your assumption about the behavior of Kubernetes (&quot;restarting the program&quot;) is correct.</p>
<p>As you may know, a Job is basically a Kubernetes Pod that executes some process and successfully finishes when it <em>exits with a zero exit code</em>. The &quot;Cron&quot; part of CronJob is the most obvious, scheduling the Job to execute in a particular time pattern.</p>
<p>Most YAML objects for CronJobs include the <code>restartPolicy: OnFailure</code> key that prevents Kubernetes from rescheduling the Job for a <strong>non-zero exit code</strong> (the <a href="https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/#example" rel="nofollow noreferrer">hello-world YAML file</a> in Kubernetes documentation uses this flag).</p>
<p>From what I see in the logs obtained by your <code>kubectl</code> instruction, it looks like your Job is failing - because of the <code>Status 1</code>. I would recommend you check the logs of the CronJob using <code>kubectl logs -f -n default job-1593017820-tt2sn</code> for any possible errors in the execution of your script (if your script explicitly exits with an exit-code, check for a possible non-zero code).</p>
<p>[UPDATE]</p>
<p>CronJobs also have limitations:</p>
<blockquote>
<p>A cron job creates a job object about once per execution time of its schedule. We say “about” because there are certain circumstances where two jobs might be created, or no job might be created. We attempt to make these rare, but do not completely prevent them. Therefore, jobs should be idempotent.</p>
</blockquote>
<p>I think these are pretty rare scenarios, but maybe you've found yourself in these rare situations. The documentation is <a href="https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/#cron-job-limitations" rel="nofollow noreferrer">here</a>.</p>
