<p>What is the default node affinity of a Cron job pod? How can we set it manually?</p>
<p>I have a pod and have set its affinity to node3.</p>
<p>However, the cron job container is still getting completed on node1 all the time when it triggers.</p>

Ankit Sharma
<p>Essentially, in your CronJob spec, the template is the PodSpec and that's where you need to configure the 'Node Affinity'. For example,</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: batch/v1beta1
kind: CronJob
metadata:
  name: hello
spec:
  schedule: &quot;*/1 * * * *&quot;
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: hello
            image: busybox
            args:
            - /bin/sh
            - -c
            - date; echo Hello from the Kubernetes cluster
          restartPolicy: OnFailure
          nodeSelector: 👈
            name: node3 👈
</code></pre>
<p>This is assuming the label 🏷️ in your node is <code>name=node3</code>.</p>
