Question on practice-test-manual-scheduling-2 , question 4. Why it does not work with NodeSelector field after adding the label to the node?
Hi @Samir Could you be a bit more specific on you question? The reference to a particular test is nice, but you might get a quicker answer if you were to articulate the question without the need to going through that test reference.
What was the requested task and what did you do that did not work?
they wanted that i add a pod to a specific node. I added a label to the node and used NodeSelector field in the definition-pod.yaml. But that does not work. The solution told me to add the Nodename/Nodefield (does not remember the attribute correctly atm) . I don’t see the difference
Something like this? That’s the way.
apiVersion: v1 kind: Pod metadata: name: nginx labels: env: test spec: containers: - name: nginx image: nginx imagePullPolicy: IfNotPresent nodeSelector: disktype: ssd
Notice the lower case nodeSelector:
yeah i did it like this
but it was like the only correct answer is:
nodeName: foo-node # schedule pod to specific node
- name: nginx
That’s a bit different. The first one that I posted will deploy into any node that contains the label
disktype with the value
ssd. Assuming that the
Taint (if any) in the node allows it.
The second one, as you posted, it will deploy into the node (host) named foo-node, if the
Taint in the node is agreeable.
In both cases, check that there are no Taints in the host that will prevent the pod to deploy.
@Fernando Jimenez nodeName will not ensure it always ? I mean even if the taint is present nodeName will ensure to deploy on the given node.
@Rahul B You are correct! I misspoke there.
@Samir you have to put a toleration on the pod not nodeName
tolerations: - key: "key1" operator: "Equal" value: "value1" effect: "NoSchedule"
no the correct answer was nodename
Another way is to put toleration with node affinity as toleration only will not ensure it
@Fernando Jimenez I still do not understand the role of nodeSelector if it does not ensure it and requires a toleration too with it ? So toleration and nodeSelector will ensure it ?
Or we need to remove the taint from node. But again removing taint is not recommened as it can disturb other pods around it .
@Rahul B Yeah, in reality you do not want to mess up with removing taints from the nodes.
Scheduling manually is something you do NOT do very often, that’s why I forgot, that for nodeName, the taints will not apply. However, to ensure that a pod will be deploy always in the node(s) you want, it is required the combination of node affinity and tolerations. Still if any of the matching nodes do not have the capacity to accommodate the pod, the pod will show as Pending in the STATUS.
to keep it simple …anything that goes through a scheduler will go through all the checks like tains , toleration etc . if you use NodeName it does not use the scheduler the pods directly go on the node so no checkes are made … etc … this is my understanding .