Skip to content
LF Cert Trainer

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

1/10Scheduler profiles
0:00 / 3:50

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

One scheduler, two profileskube-scheduler (one process)defaultby namespreadpackPod webno schedulerNamePod batchasks for bin-packingdefault-schedulerdefault pluginsbin-packingprefers full nodesnode-1almost emptynode-2almost full
One scheduler, two profiles. Both profiles live in the same kube-scheduler process and share its queue and its view of the nodes. The Pod's schedulerName picks the profile.

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:

PartFieldWhat it does
A nameschedulerNameThe name Pods use in spec.schedulerName. Must be unique in the file
Which plugins runpluginsPer extension point, lists of plugins to enable or disable, with weights for scoring
Plugin argumentspluginConfigSettings 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 profilesSeveral schedulers
Processes to runOneOne per scheduler
View of free capacityShared, always consistentSeparate, can conflict
Custom codeOnly plugins compiled into kube-schedulerAny scheduler binary you like
How a Pod choosesspec.schedulerNamespec.schedulerName
A broken configuration stopsEvery profileOnly 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:

  1. queueSort
  2. preFilter
  3. filter
  4. postFilter
  5. preScore
  6. score
  7. reserve
  8. permit
  9. preBind
  10. bind
  11. postBind
One Pod through the extension points
Plugins plug into extension pointsno0-100TaintTolerationfilter and scoreNodeResourcesFitfilter and scoreImageLocalityscore onlyfiltercan the Pod run here?scorehow good is this node?Nodes removedhard yes or noNodes rankedweighted total wins
Plugins plug into extension points. A plugin implements one or more extension points. A profile is the list of which plugins run at each point, and with what weight.

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 pointWhat its plugins doDefault plugins you will recognise
queueSortOrder the pending Pods. Exactly one pluginPrioritySort
preFilter, filterRemove nodes that cannot run the PodNodeResourcesFit, TaintToleration, NodeAffinity, NodeUnschedulable, NodePorts, NodeName
postFilterRun only when no node passedDefaultPreemption
preScore, scoreGive each remaining node 0 to 100 points, times the plugin's weightNodeResourcesFit, NodeResourcesBalancedAllocation, ImageLocality, TaintToleration, NodeAffinity, PodTopologySpread, InterPodAffinity
reserve, permit, preBindHold resources, delay or prepare the bindingVolumeBinding
bindWrite the node into the Pod. At least one pluginDefaultBinder

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:

  • disabled removes default plugins; - name: "*" removes all of them for that extension point.
  • enabled adds plugins, in the order they are called. weight only means something for score.
  • 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

How the configuration reaches the schedulermounted aswatchedstartsreadbuildsscheduler-config.yamlin /etc/kubernetesStatic Pod manifestkube-scheduler.yamlkubeletrestarts the PodhostPath volumefile, read onlykube-scheduler--config=<file>Profilesone per schedulerName
How the configuration reaches the scheduler. On a kubeadm cluster the scheduler is a static Pod. The file must exist on the control plane node, be mounted into the container, and be named by the --config flag.

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 saysCauseFix
no such file or directory for the config pathThe file is not mounted, or the paths differMake --config, mountPath and hostPath.path agree
A plugin does not existMisspelled plugin name (names are case sensitive)Correct the name in plugins or pluginConfig
No kubeconfig, or it tries to use in-cluster configurationclientConnection.kubeconfig is missingAdd it to the configuration file
An error about queueSortProfiles use different queue sort pluginsUse the same one in every profile
The kubelet cannot parse the manifestBroken YAML indentation in the manifestFix 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 apply the configuration. KubeSchedulerConfiguration is 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 hostPath volume and the volumeMount, the scheduler exits because the file does not exist.
  • Forgetting clientConnection.kubeconfig. With --config set, the --kubeconfig flag 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/manifests and back.
  • Misspelling the profile name in the Pod. A schedulerName that matches no profile gives a Pod that is Pending for ever with no events. schedulerName cannot 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 under pluginConfig.
  • Profiles share one process, one queue and one view of the nodes, so they must agree on queueSort and they fail together.
  • The file is a KubeSchedulerConfiguration passed with --config; on kubeadm, mount it into the static Pod and set clientConnection.kubeconfig.
  • Verify with a test Pod: the Scheduled event 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.