Question on practice-test-manual-scheduling-2 , question 4. Why it does not work . . .

Samir:
Question on practice-test-manual-scheduling-2 , question 4. Why it does not work with NodeSelector field after adding the label to the node?

Fernando Jimenez:
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?

Samir:
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

Fernando Jimenez:
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

Fernando Jimenez:
Notice the lower case nodeSelector:

Samir:
yeah i did it like this

Samir:
but it was like the only correct answer is:

apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
nodeName: foo-node # schedule pod to specific node
containers:
- name: nginx
image: nginx
imagePullPolicy: IfNotPresent

Fernando Jimenez:
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.

Fernando Jimenez:
In both cases, check that there are no Taints in the host that will prevent the pod to deploy.

Rahul B:
@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.

Fernando Jimenez:
@Rahul B You are correct! I misspoke there.

Hinodeya:
@Samir you have to put a toleration on the pod not nodeName

Hinodeya:
check this

tolerations:
- key: "key1"
  operator: "Equal"
  value: "value1"
  effect: "NoSchedule"

Samir:
no the correct answer was nodename

Fernando Jimenez:
You mean:

 nodeName

Samir:
yeah sorry :eyes:

Rahul B:
Another way is to put toleration with node affinity as toleration only will not ensure it

Rahul B:
@Fernando Jimenez I still do not understand the role of nodeSelector :slightly_smiling_face: 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 .

Fernando Jimenez:
@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.

Madhan Kumar:
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 .