Section 2: Scheduling
Section 2: Scheduling
Manual scheduling
● Manual scheduling is manual defining the node onto which the pod will
be placed on. This can useful when kube-scheduler is not active.
● Property nodeName is defined in the spec section of the pod
definition file.
○ Example :-
◆ nodeName : node01
◆ nodeName : controlplane
● Labels and selectors are used to filter k8s objects such as pods with
their labels based on a criteria.
● To filter them the --selector option is used.
○ Example :-
◆ k get pods --selector label=value
◆ k get pods --selector
label=value,label=value,label=value,…n
that does not tolerate the taint on the node, but it is not
required.
◆ NoExecute : new pods will not be scheduled on the node and
Node selector
● Node selectors are placed on pods in order to make sure that pods are
schedule only on node with the specified labels.
○ To label a node use command :-
◆ k label node node-name label-key=label-value
○ Now that we have labeled the node we can create a pod with
nodeSelector property.
◆ nodeSelector:
label-key: label-value
○ This places the pod on node with the defined labels.
● Node affinity allows you to constrain which nodes your Pod can be
scheduled on based on node labels.
● This provides advanced capability to limit pod placement on specific
nodes, in cases where we consider many conditions.
○ As on node selector, we first make sure that nodes are labeled.
○ Then set node affinity rules to match the labels.
◆ affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: <key-1>
operator: In | Exists
values:
- <value-1>
● Using either taints and tolerations or node affinity rules alone cannot
100% guarantee that nodes are only dedicated to specific pods or that
pods will only be scheduled on specific nodes.
● A combination of taints & tolerations and node affinity rules can be
used together to completely dedicate nodes to specific pods.
○ Steps :-
Resource limits
● PODS
○ These are defined as resources in the spec.containters. section
requests:
memory: “1Gi”
cpu: 1
limits:
memory: “2Gi”
cpu: 2
○ Default values for cpu is .5 and memory is 256 Mi.
DaemonSets
● DaemonSets are used to deploy one copy of a pod on each node. They
work as replicaSets.
● This is useful when deploying monitoring or logging agents, kube-
proxy and networking solutions such as weave-net.
○ The definition file is exactly similar to the one of replicaSets,
Static pods
Multiple schedulers
● In some cases, the default Kubernetes scheduler may not fit your need
and you may want to deploy your own custom scheduler.
● You can deploy your own custom scheduler by configuring the
●
following :-
. Kube Scheduler Configuration
. ConfigMap
. Service Account
. ClusterRoleBinding as Kube scheduler
. ClusterRoleBinding as volume scheduler
. RoleBinding to authenticate to Kube API Server
. Deployment for the custom scheduler
filtered out.
. Scoring phase
◆ Nodes are scored with different weights such as storage space
. Scheduling queue
– PrioritySort : checks if a pod has priority property set on it.
. Filtering phase
– NodeResourcesFit : identifies the nodes with sufficient
resources required by the pod and filters our the ones that
doesn’t.
– NodeName : checks if a pod has nodeName property set on it
and filters out all other nodes with different names.
– NodeUnschedulable : filters out nodes which has
unschedulable option set true. This are drained / cordoned
–
nodes.
– TaintToleration : checks for taints on nodes and tolerations on
pods.
– NodeAffinity : checks for node affinity rules on pods.
. Scoring phase
– NodeResourcesFit : identifies the nodes with sufficient
resources required by the pod and associates a high score to
nodes with much resources.
– ImageLocality : associates a high score to each node that
already has the container image to be used by the pod.
◆ If there is no node with the image this plugin will be
ignored.
. Binding phase
– DefaultBinder : provides the binding mechanism.
○ All the above plugins are used in the 4 phases with help of
extension points on each scheduling phase. This are points to
which a plugin can be plugged to in order to be used in that
particular phase. Some plugins span across multiple extension
points.
○ Extensions include :-
◆ Scheduling queue
. QueueSort
◆ Filtering phase
. preFilter
. filter
. postFilter
◆ Scoring phase
. preScore
. score
. reserve
◆ Scheduling queue
. permit
. preBind
. bind
. postBind
● How can we change the default behavior of how the plugins are
called(invoked) or how to create our own plugins.