Kube-Scheduler in Kubernetes

Kube-Scheduler is responsible for scheduling pods on nodes. The scheduler is only responsible for deciding which pod and which node. It does not actually place the pods on the nodes. That is the job of the Kubelet.

Why do we need a Kube-Scheduler?

When there are many containers, you want to make sure that the right container ends up on the nodes. There could be different resources in the nodes. You want to make sure the node has sufficient capacity to accommodates those containers.

In Kubernetes, the Kube-scheduler decides which nodes the pods are placed on depending on certain criteria. You may have Pods with different resource requirements, you can have nodes in the cluster dedicated to certain applications.

How does the Kube-scheduler assign these pods?

The scheduler looks at each pod and tries to find the best node for it.

  1. Filter Nodes
    • The Kube-scheduler tries to filter out the nodes that do not fit the profile for the pod. (the nodes that do not have sufficient CPU and memory resources requested by the pod).
  2. Rank Nodes
    • The Kube-scheduler ranks the node to identify the best fit for the pod. It uses a priority function to assign a score to the nodes on a scale of 0 to 10.
  3. More
    • More resource requirements and limits
    • Taints and tolerations
    • Node Selectors/Affinity

Kube-Scheduler with Kubeadm

$ kubectl get pods -n kube-system
NAME                                 READY   STATUS    RESTARTS   AGE
coredns-f9fd979d6-wtk5k              1/1     Running   1          7d
coredns-f9fd979d6-x5zxv              1/1     Running   1          7d
etcd-kubemaster                      1/1     Running   1          7d
kube-apiserver-kubemaster            1/1     Running   1          7d
kube-controller-manager-kubemaster   1/1     Running   1          7d
kube-proxy-jnf5q                     1/1     Running   1          6d23h
kube-proxy-m9krm                     1/1     Running   1          6d23h
kube-proxy-zfbsh                     1/1     Running   1          7d
kube-scheduler-kubemaster            1/1     Running   1          7d
weave-net-g4l7r                      2/2     Running   3          7d
weave-net-skdlq                      2/2     Running   4          6d23h
weave-net-xg67h                      2/2     Running   4          6d23h
  • kube-scheduler-kubemaster

Kube-Scheduler pod definition file information with Kubeadm

$ cat /etc/kubernetes/manifests/kube-scheduler.yaml 
apiVersion: v1
kind: Pod
metadata:
  creationTimestamp: null
  labels:
    component: kube-scheduler
    tier: control-plane
  name: kube-scheduler
  namespace: kube-system
spec:
  containers:
  - command:
    - kube-scheduler
    - --authentication-kubeconfig=/etc/kubernetes/scheduler.conf
    - --authorization-kubeconfig=/etc/kubernetes/scheduler.conf
    - --bind-address=127.0.0.1
    - --kubeconfig=/etc/kubernetes/scheduler.conf
    - --leader-elect=true
    - --port=0
    image: k8s.gcr.io/kube-scheduler:v1.19.4
    imagePullPolicy: IfNotPresent
    livenessProbe:
      failureThreshold: 8
      httpGet:
        host: 127.0.0.1
        path: /healthz
        port: 10259
        scheme: HTTPS
      initialDelaySeconds: 10
      periodSeconds: 10
      timeoutSeconds: 15
    name: kube-scheduler
    resources:
      requests:
        cpu: 100m
    startupProbe:
      failureThreshold: 24
      httpGet:
        host: 127.0.0.1
        path: /healthz
        port: 10259
        scheme: HTTPS
      initialDelaySeconds: 10
      periodSeconds: 10
      timeoutSeconds: 15
    volumeMounts:
    - mountPath: /etc/kubernetes/scheduler.conf
      name: kubeconfig
      readOnly: true
  hostNetwork: true
  priorityClassName: system-node-critical
  volumes:
  - hostPath:
      path: /etc/kubernetes/scheduler.conf
      type: FileOrCreate
    name: kubeconfig
status: {}

Leave a Reply

Your email address will not be published.

ANOTE.DEV