Lesson 39 · Section 3: Scheduling
Lesson 39: Scheduler profiles: several scheduling behaviours from one kube-scheduler
What a scheduler profile is, how plugins and extension points make up a profile, how to write a KubeSchedulerConfiguration with several profiles, and how to load and verify it on a kubeadm cluster. · 20 min read · 4 min video
Official competencies this lesson covers
Narrated by the local narrator voice. Keys: Space plays and pauses, J and L step, C captions, F full screen.
Why profiles exist
The default scheduler treats every Pod the same way: filter out the nodes that cannot run it, then prefer the node with the most free resources. That is a good default for long-running services, because it spreads load. It is a poor fit for other workloads. Batch jobs are cheaper when they are packed onto as few nodes as possible, so the empty nodes can be removed. Some teams want image locality to count for more, or do not want it to count at all.
One answer is to run a second scheduler, which is what the Multiple Schedulers lesson shows. It works, but it has a price: a second Deployment to run and upgrade, a second set of permissions, and two programs that each keep their own picture of the cluster. Two schedulers can both decide that the last free CPU on a node is theirs to give away; one of the two Pods is then rejected by the kubelet.
Scheduler profiles solve the same problem inside the scheduler you already have. One kube-scheduler process can serve several scheduler names, each with its own set of rules.
What a profile is
Parts:
- Pod web (no schedulerName)
- Pod batch (asks for bin-packing)
- default-scheduler (default plugins), in kube-scheduler (one process)
- bin-packing (prefers full nodes), in kube-scheduler (one process)
- node-1 (almost empty)
- node-2 (almost full)
Connections:
- Pod web to default-scheduler: default
- Pod batch to bin-packing: by name
- default-scheduler to node-1: spread
- bin-packing to node-2: pack
A profile has three parts:
| Part | Field | What it does |
|---|---|---|
| A name | schedulerName | The name Pods use in spec.schedulerName. Must be unique in the file |
| Which plugins run | plugins | Per extension point, lists of plugins to enable or disable, with weights for scoring |
| Plugin arguments | pluginConfig | Settings for a single plugin, such as the scoring strategy of NodeResourcesFit |
Everything you leave out keeps its default. A profile that only has a schedulerName behaves exactly like the
default scheduler under another name.
Profiles are not separate schedulers. They share one process, one queue of pending Pods, one cache of the nodes and one leader election lock. That is why they cannot double-book a node the way two independent schedulers can.
| Several profiles | Several schedulers | |
|---|---|---|
| Processes to run | One | One per scheduler |
| View of free capacity | Shared, always consistent | Separate, can conflict |
| Custom code | Only plugins compiled into kube-scheduler | Any scheduler binary you like |
| How a Pod chooses | spec.schedulerName | spec.schedulerName |
| A broken configuration stops | Every profile | Only that scheduler |
How it works: plugins and extension points
The scheduler does not have one big algorithm. It walks each Pod through a fixed series of stages, called extension points, and at each stage it calls the plugins registered there:
- queueSort
- preFilter
- filter
- postFilter
- preScore
- score
- reserve
- permit
- preBind
- bind
- postBind
Parts:
- TaintToleration (filter and score)
- NodeResourcesFit (filter and score)
- ImageLocality (score only)
- filter (can the Pod run here?)
- score (how good is this node?)
- Nodes removed (hard yes or no)
- Nodes ranked (weighted total wins)
Connections:
- TaintToleration to filter
- NodeResourcesFit to filter
- NodeResourcesFit to score
- ImageLocality to score
- TaintToleration to score
- filter to Nodes removed: no
- score to Nodes ranked: 0-100
| Extension point | What its plugins do | Default plugins you will recognise |
|---|---|---|
queueSort | Order the pending Pods. Exactly one plugin | PrioritySort |
preFilter, filter | Remove nodes that cannot run the Pod | NodeResourcesFit, TaintToleration, NodeAffinity, NodeUnschedulable, NodePorts, NodeName |
postFilter | Run only when no node passed | DefaultPreemption |
preScore, score | Give each remaining node 0 to 100 points, times the plugin's weight | NodeResourcesFit, NodeResourcesBalancedAllocation, ImageLocality, TaintToleration, NodeAffinity, PodTopologySpread, InterPodAffinity |
reserve, permit, preBind | Hold resources, delay or prepare the binding | VolumeBinding |
bind | Write the node into the Pod. At least one plugin | DefaultBinder |
A plugin can serve several extension points. NodeResourcesFit is both a filter (do the requests fit?) and a score
(how full would the node be?). TaintToleration filters on NoSchedule taints and scores on PreferNoSchedule
taints. These are the same features you configure on Pods and nodes in the rest of this section; a profile decides
whether each one runs and how much its score counts.
The node's final score is the weighted sum over all score plugins:
total(node) = Σ weight(plugin) × score(plugin, node) score is 0 to 100
So there are three ways to change scheduling behaviour in a profile: disable a plugin, change its weight, or change its arguments.
Under the hood · multiPoint: one switch for all of a plugin's extension points
A plugin such as PodTopologySpread is registered at four extension points. Listing it four times is tedious, so
the plugins block also accepts a multiPoint list. A plugin enabled under multiPoint is registered at every
extension point it implements, and the default plugins are themselves configured this way.
profiles:
- schedulerName: no-spread
plugins:
multiPoint:
disabled:
- name: PodTopologySpread # off at preFilter, filter, preScore and score
Precedence is: settings on a specific extension point first, then your own multiPoint entries, then the defaults.
So you can enable a plugin everywhere with multiPoint and still switch it off for score alone.
Writing the configuration
Profiles are written in a KubeSchedulerConfiguration file. It is a configuration file for the kube-scheduler
binary, not an API object: you cannot kubectl apply it. The scheduler reads it once, at start, from the path given
with --config.
apiVersion: kubescheduler.config.k8s.io/v1
kind: KubeSchedulerConfiguration
clientConnection:
kubeconfig: /etc/kubernetes/scheduler.conf # needed: --kubeconfig is ignored when --config is set
profiles:
- schedulerName: default-scheduler # unchanged defaults, for every Pod that names no scheduler
- schedulerName: bin-packing
pluginConfig:
- name: NodeResourcesFit
args:
scoringStrategy:
type: MostAllocated # default is LeastAllocated
resources:
- name: cpu
weight: 1
- name: memory
weight: 1
Enabling and disabling plugins happens under plugins, one block per extension point:
profiles:
- schedulerName: custom-scoring
plugins:
score:
disabled:
- name: ImageLocality # stop preferring nodes that have the image
- name: TaintToleration
enabled:
- name: TaintToleration # disabled and enabled again: same plugin, new weight
weight: 5
preScore:
disabled:
- name: "*" # every default plugin at this extension point
The rules that matter:
disabledremoves default plugins;- name: "*"removes all of them for that extension point.enabledadds plugins, in the order they are called.weightonly means something forscore.- To change the weight of a default plugin, disable it and enable it again with the new weight.
- Plugin names are case sensitive and must exist in the binary. Only plugins compiled into kube-scheduler can be named; a profile cannot load new code.
Loading it on a kubeadm cluster
Parts:
- scheduler-config.yaml (in /etc/kubernetes)
- Static Pod manifest (kube-scheduler.yaml)
- kubelet (restarts the Pod)
- hostPath volume (file, read only)
- kube-scheduler (--config=<file>)
- Profiles (one per schedulerName)
Connections:
- scheduler-config.yaml to hostPath volume: mounted as
- Static Pod manifest to kubelet: watched
- kubelet to kube-scheduler: starts
- hostPath volume to kube-scheduler: read
- kube-scheduler to Profiles: builds
On a kubeadm cluster the scheduler runs as a static Pod, in a container that only sees the files mounted into it. Three things have to line up: the file exists on the control plane node, the manifest mounts it, and the command names it.
# /etc/kubernetes/manifests/kube-scheduler.yaml (only the lines you add)
spec:
containers:
- name: kube-scheduler
command:
- kube-scheduler
- --config=/etc/kubernetes/scheduler-config.yaml
# the existing flags stay as they are
volumeMounts:
- name: scheduler-config
mountPath: /etc/kubernetes/scheduler-config.yaml
readOnly: true
volumes:
- name: scheduler-config
hostPath:
path: /etc/kubernetes/scheduler-config.yaml
type: File
When you save the manifest, the kubelet recreates the scheduler Pod within a few seconds. The scheduler reads the file once. A later change to the configuration file alone does nothing until the scheduler restarts.
Using it
Example · Add a bin-packing profile to the cluster's scheduler
You are asked to add a profile named bin-packing that prefers the fullest node, without changing how other Pods
are scheduled. Work on the control plane node.
ssh controlplane
sudo cp /etc/kubernetes/manifests/kube-scheduler.yaml /root/kube-scheduler.yaml.bak # backup OUTSIDE manifests
sudo vi /etc/kubernetes/scheduler-config.yaml
apiVersion: kubescheduler.config.k8s.io/v1
kind: KubeSchedulerConfiguration
clientConnection:
kubeconfig: /etc/kubernetes/scheduler.conf
profiles:
- schedulerName: default-scheduler
- schedulerName: bin-packing
pluginConfig:
- name: NodeResourcesFit
args:
scoringStrategy:
type: MostAllocated
resources:
- name: cpu
weight: 1
- name: memory
weight: 1
Now edit the manifest: add the --config flag, the volumeMount and the hostPath volume shown in the section
above.
sudo vi /etc/kubernetes/manifests/kube-scheduler.yaml
watch sudo crictl ps --name kube-scheduler # wait for a new container that stays Running
kubectl -n kube-system get pods -l component=kube-scheduler
Example · Schedule a Pod with the new profile and prove it
Only one line in the Pod chooses the profile:
apiVersion: v1
kind: Pod
metadata:
name: batch
spec:
schedulerName: bin-packing
containers:
- name: batch
image: busybox:1.37
command: ["sleep", "3600"]
resources:
requests:
cpu: 100m
memory: 64Mi
Each profile reports events under its own name, so the Scheduled event tells you which one placed the Pod:
kubectl apply -f batch.yaml
kubectl get events --field-selector involvedObject.name=batch,reason=Scheduled \
-o custom-columns=FROM:.reportingComponent,MESSAGE:.message
FROM MESSAGE
bin-packing Successfully assigned default/batch to node-2
Give the test Pod resource requests. MostAllocated and LeastAllocated score nodes by requested CPU and memory, so
they can only tell nodes apart when requests are set.
Example · Repair a scheduler that does not start after a configuration change
After the edit, new Pods stay Pending with no events, and the scheduler Pod is missing or restarting. Ask the
container runtime why, because kubectl logs may have nothing to show:
sudo crictl ps -a --name kube-scheduler # newest container: Exited?
sudo crictl logs <container-id> 2>&1 | tail -n 5
sudo journalctl -u kubelet --since "5 min ago" | grep -i scheduler
Read the last lines of the log and match them to the usual causes:
| What the log or the kubelet says | Cause | Fix |
|---|---|---|
no such file or directory for the config path | The file is not mounted, or the paths differ | Make --config, mountPath and hostPath.path agree |
A plugin does not exist | Misspelled plugin name (names are case sensitive) | Correct the name in plugins or pluginConfig |
| No kubeconfig, or it tries to use in-cluster configuration | clientConnection.kubeconfig is missing | Add it to the configuration file |
An error about queueSort | Profiles use different queue sort plugins | Use the same one in every profile |
| The kubelet cannot parse the manifest | Broken YAML indentation in the manifest | Fix the manifest, or restore your backup |
If you run out of time, restore the backup. A working default scheduler is worth more than a half-finished profile:
sudo cp /root/kube-scheduler.yaml.bak /etc/kubernetes/manifests/kube-scheduler.yaml
Tricks
Common mistakes
- Trying to
kubectl applythe configuration.KubeSchedulerConfigurationis a file for the scheduler binary, not a resource in the API. It is read from disk through--config. - Creating the file but not mounting it. The scheduler container cannot see the node's file system. Without the
hostPathvolume and thevolumeMount, the scheduler exits because the file does not exist. - Forgetting
clientConnection.kubeconfig. With--configset, the--kubeconfigflag in the kubeadm manifest no longer counts, and the scheduler cannot sign in to the API server. - Editing the file and expecting an immediate effect. The file is read at start. Restart the scheduler, for
example by moving the manifest out of
/etc/kubernetes/manifestsand back. - Misspelling the profile name in the Pod. A
schedulerNamethat matches no profile gives a Pod that is Pending for ever with no events.schedulerNamecannot be edited on a live Pod; recreate it. - Assuming one broken profile only hurts its own Pods. All profiles live in one process. A configuration error in any profile keeps the whole scheduler down, and nothing in the cluster is scheduled.
- Using profiles to run custom code. A profile can only arrange plugins that are compiled into the scheduler. For your own scheduling logic you need your own scheduler binary, run as a second scheduler.
Recap
- A profile is a named set of plugin settings inside one kube-scheduler; Pods choose it with
spec.schedulerName. - Scheduling runs through extension points; plugins do the work at each one. A profile enables, disables and
weights them under
plugins, and tunes them underpluginConfig. - Profiles share one process, one queue and one view of the nodes, so they must agree on
queueSortand they fail together. - The file is a
KubeSchedulerConfigurationpassed with--config; on kubeadm, mount it into the static Pod and setclientConnection.kubeconfig. - Verify with a test Pod: the
Scheduledevent is reported under the profile's name.
Official docs
Quiz: check what you learned
5 questions on this lesson · about 3 min · instant feedback. Missed questions come back in your review queue.
Sign in to take the quiz and keep your score.
Discussion
Learners ask and answer questions here. Sign in to read and join the discussion.