<p>We are running a daily cronjob on GKE. This job is executed on spot nodes. The container respects the <code>SIGTERM</code> and gracefully shuts down. However, this is then marked as successful and not restarted. How can I ensure that this job is restarted on a different node?</p>
<p>I've read <a href="https://kubernetes.io/docs/concepts/architecture/nodes/#graceful-node-shutdown" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/architecture/nodes/#graceful-node-shutdown</a> and <a href="https://kubernetes.io/docs/concepts/workloads/controllers/job/#handling-pod-and-container-failures" rel="nofollow noreferrer">https://kubernetes.io/docs/concepts/workloads/controllers/job/#handling-pod-and-container-failures</a>, but I see nothing in there that helps me.</p>

Rhand
<p>By default the cron jobs in kubernetes are not rescheduled after a node shutdown. However you can configure the job to use a <code>restartPolicy</code> of <code>OnFailure</code> to ensure that it is rescheduled after a node shutdown.</p>
<p>You need to mention the restartPolicy in spec sections as follows</p>
<pre><code>apiVersion: batch/v1
kind: CronJob
metadata:
 name: myjob
spec:
 schedule: &quot;* * * * *&quot;
 jobTemplate:
  spec:
   template:
    spec:
     containers:
       - name: myjob
         image: nginx
         imagePullPolicy: IfNotPresent
     restartPolicy: OnFailure
</code></pre>
<p>By using this <strong>restartPolicy</strong>, if a node is shutdown or the pod running the cron job terminates for any reason, the kubernetes scheduler will automatically reschedule the cronjob to run a healthy node.</p>
<p><strong>Note:</strong> It is important to ensure that the cronjob required resources are available in the node.</p>
