How Kubernetes
Scheduler works
Himani Agrawal
@himani_93
Agenda
● Scheduling in Kubernetes
● Scheduler use cases
● How it works?
● Demo
● New in scheduler
Credits: Julia Evans (@b0rk)
In Kubernetes, scheduling
refers to making sure that
Pods are matched to Nodes
so that Kubelet can run
them.
Ref: https://kubernetes.io/docs/concepts/scheduling/kube-scheduler/
Credits: https://cloud.google.com/kubernetes-engine/kubernetes-comic/
What can be achieved through scheduler?
● Ensure pods gets required resources
● Prioritize workload
● Configure geographical distance
● Reserve nodes for specific pods
Credits: https://cloud.google.com/kubernetes-engine/kubernetes-comic/
What scheduler needs?
1 2 3
Need to know a pod is NOT
assigned to a node
Choose a best fit node on
which the pod can run Assign the pod to the node
What scheduler needs?
1 2 3
Need to know a pod is NOT
assigned to a node
Choose a best fit node on
which the pod can run Assign the pod to the node
Scheduler is basically
a Kubernetes
Controller
Kubernetes Controller
Current state Takes necessary actions
so that desired state is
achieved
Once desired state is
achieved, it updates the
state of resources
This continuously runs in a loop
Credits: LEGO
What scheduler needs?
1 2 3
Need to know a pod is NOT
assigned to a node
Choose a best fit node on
which the pod can run Assign the pod to the node
What scheduler needs?
1 2 3
Need to know a pod is NOT
assigned to a node
Choose a best fit node on
which the pod can run
Fi2
Assign the pod to the node
a Filtering
Filtering
4 5 6
1 2 3
Pod manifest
apiVersion: "v1"
kind: Pod
metadata:
name: sansa
spec:
nodeName: ""
containers:
image: busybox
Filtering
4 5 6
2 31
Filtering
4 5 6
2 31
4 5 6
1 2 3
4 5 6
1 2 3
10
7 8 9
4 5 6
1 2 3
10
7 8 9
4 5 6
1 2 3
10
7 8 9
4 5 6
1 2 3
10
7 8 9
4 5 6
1 2 3
10
7 8 9
4 5 6
1 2 3
10
7 8 9
percentageOfNodesToScore
4 5 6
1 2 3
10
7 8 9
What scheduler needs?
1 2 3
Need to know a pod is NOT
assigned to a node
Choose a best fit node on
which the pod can run
Fi2
Assign the pod to the node
a Filtering
b Scoring
3
1
2
8
What scheduler needs?
1 2 3
Need to know a pod is NOT
assigned to a node
Choose a best fit node on
which the pod can run Assign the pod to the node
Binding
apiVersion: "v1"
kind: Pod
metadata:
name: sansa
spec:
nodeName: "8"
containers:
image: busybox
API Server Scheduler Kubelet
create pod
watch (create pod)
create binding
watch (create bind)
Container
Engine
create container
apiVersion: "v1"
kind: Pod
metadata:
name: sansa
spec:
image: busybox
Pod Manifest
How event triggering happens?
Demo
Picture Credits: Ashley McNamara
Demo
● nodeSelector
● nodeAffinity
● podAffinity
● taints and tolerations
What else?
● Extensible, https://kubernetes.io/docs/reference/command-line-tools-reference/kube-scheduler/
● Custom Scheduler, https://kubernetes.io/docs/tasks/administer-cluster/configure-multiple-schedulers/
● Even Pod Spreading, https://github.com/kubernetes/enhancements/blob/master/keps/sig-
scheduling/20190221-even-pods-spreading.md
● Scheduling Framework, https://github.com/kubernetes/enhancements/blob/master/keps/sig-
scheduling/20180409-scheduling-framework.md
● Batch Scheduling
https://github.com/kubernetes/enhancements/blob/master/keps/sig-scheduling/34-20180703-
coscheduling.md
References
● Kubernetes Community Docs
● https://jvns.ca/blog/2017/07/27/how-does-the-kubernetes-scheduler-work/
● What Happens when k8s
Getting Involved
➔ Github Repo
https://github.com/kubernetes/kubernetes/tree/master/pkg/s
cheduler
➔ Mailing List: kubernetes-sig-scheduling
https://groups.google.com/forum/#!forum/kubernetes-sig-
scheduling
➔ Slack: #sig-scheduling
https://kubernetes.slack.com/messages/C8TSNPY4T
Merci beaucoup
@himani_93

How Kubernetes scheduler works