Reputation: 513
What is the default node affinity of a Cron job pod? How can we set it manually?
I have a pod and have set its affinity to node3.
However, the cron job container is still getting completed on node1 all the time when it triggers.
Upvotes: 6
Views: 6141
Reputation: 61561
Essentially, in your CronJob spec, the template is the PodSpec and that's where you need to configure the 'Node Affinity'. For example,
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: hello
spec:
schedule: "*/1 * * * *"
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 👈
This is assuming the label 🏷️ in your node is name=node3
.
Upvotes: 5