Home > Mobile >  nodeSelector doesn't match the target node
nodeSelector doesn't match the target node

Time:08-06

I want to deploy a simple nginx on my master node.

Basically, if i use the tolerations combined by nodeName everything is good:

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: myapp
  name: myapp-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
      - image: nginx
        name: myapp-container
      tolerations:
        - effect: NoExecute
          operator: Exists
      nodeName: master

The results:

NAME                               READY   STATUS    RESTARTS   AGE   IP           NODE     NOMINATED NODE   READINESS GATES
myapp-deployment-56d5887b9-fw5mj   1/1     Running   0          50s   100.32.0.4   master   <none>           <none>

But the problem is when i add a type=master label to my node and instead of nodeName, useing nodeselector, the deployment stays in Pending state!

Here are my steps:

  1. Add label to my node: k label node master type=master
  2. Check the node label:
$ k get no --show-labels

NAME     STATUS   ROLES           AGE   VERSION   LABELS
master   Ready    control-plane   65d   v1.24.1   beta.kubernetes.io/arch=amd64,beta.kubernetes.io/os=linux,kubernetes.io/arch=amd64,kubernetes.io/hostname=master,kubernetes.io/os=linux,node-role.kubernetes.io/control-plane=,node.kubernetes.io/exclude-from-external-load-balancers=,type=master
  1. Apply my new yaml file:
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: myapp
  name: myapp-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
      - image: nginx
        name: myapp-container
      tolerations:
        - effect: NoExecute
          operator: Exists
      nodeSelector:
        type: master
  1. Check the state:
$ k get po

NAME                                READY   STATUS    RESTARTS   AGE
myapp-deployment-544784ff98-2qf7z   0/1     Pending   0          3s
  1. Describe it:
Name:           myapp-deployment-544784ff98-2qf7z
Namespace:      default
Priority:       0
Node:           <none>
Labels:         app=myapp
                pod-template-hash=544784ff98
Annotations:    <none>
Status:         Pending
IP:             
IPs:            <none>
Controlled By:  ReplicaSet/myapp-deployment-544784ff98
Containers:
  myapp-container:
    Image:        nginx
    Port:         <none>
    Host Port:    <none>
    Environment:  <none>
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from kube-api-access-lbtsv (ro)
Conditions:
  Type           Status
  PodScheduled   False 
Volumes:
  kube-api-access-lbtsv:
    Type:                    Projected (a volume that contains injected data from multiple sources)
    TokenExpirationSeconds:  3607
    ConfigMapName:           kube-root-ca.crt
    ConfigMapOptional:       <nil>
    DownwardAPI:             true
QoS Class:                   BestEffort
Node-Selectors:              type=master
Tolerations:                 :NoExecute op=Exists
Events:
  Type     Reason            Age   From               Message
  ----     ------            ----  ----               -------
  Warning  FailedScheduling  111s  default-scheduler  0/1 nodes are available: 1 node(s) had untolerated taint {node-role.kubernetes.io/master: }. preemption: 0/1 nodes are available: 1 Preemption is not helpful for scheduling.

Where am i wrong? What is my problem?

P.S: kubernetes version:

Client Version: v1.24.1
Kustomize Version: v4.5.4
Server Version: v1.24.1

CodePudding user response:

Check your master node it might be having the taint set to NoSchedule

kubectl describe node <Node name> | grep Taint

If you want to run POD on master node use this config

tolerations:
  - key: "node-role.kubernetes.io/master"
    operator: "Exists"
    effect: "NoSchedule"
  nodeSelector:
    node-role.kubernetes.io/master: ""

Read more about the Concept taint and toleration: https://kubernetes.io/docs/concepts/scheduling-eviction/taint-and-toleration/

CodePudding user response:

Well, thanks to @Harsh, i finally finded the answer:

First i get the Taint on my master node:

$ kubectl describe node master | grep Taint

  Taints:             node-role.kubernetes.io/control-plane:NoSchedule

As you can see, the value of Taint here is NoSchedule, NOT NoExecute that i used before!

So, the configuration would be like this:

apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: myapp
  name: myapp-deployment
spec:
  replicas: 1
  selector:
    matchLabels:
      app: myapp
  template:
    metadata:
      labels:
        app: myapp
    spec:
      containers:
      - image: nginx
        name: myapp-container
      tolerations:
        - effect: "NoSchedule" # just change this
          operator: "Exists"
      nodeSelector:
        type: master

And now you can see everything is good!

NAME                                READY   STATUS    RESTARTS   AGE
myapp-deployment-79676c54d4-grm94   1/1     Running   0          7s
  • Related