Skip to content
LF Cert Trainer

Lesson 38 · Section 3: Scheduling

Lesson 38: Multiple schedulers: running a second scheduler next to the default one

Why a cluster can have more than one scheduler, how one field in the Pod spec picks between them, how to deploy a second kube-scheduler as a Deployment or a static Pod, and how to prove which scheduler placed a Pod. · 20 min read · 4 min video

1/11Multiple schedulers
0:00 / 4:18

Narrated by the local narrator voice. Keys: Space plays and pauses, J and L step, C captions, F full screen.

Why you would run more than one scheduler

The default scheduler, covered in the kube-scheduler lesson, places every Pod with one set of rules: filter out the nodes that cannot run the Pod, score the rest, prefer nodes with more room. That suits most workloads, but not all of them:

  • Different placement goals. Web servers should be spread out so a node failure hurts little. Batch jobs are cheaper when they are packed onto few nodes, so the idle ones can be removed.
  • Special logic. Machine learning and batch platforms (Volcano, YuniKorn and others) ship their own scheduler that understands queues, job groups or GPUs.
  • Trying a change safely. A new scheduler configuration can be tested on a handful of Pods while everything else stays on the scheduler you trust.

Kubernetes does not make you choose. Any number of schedulers can run side by side, and every Pod says which one it wants.

What "a scheduler" is to Kubernetes

One field decides which scheduler handles a Poddefaultbindsby namebindsno matchwaitsPod webno schedulerNamePod batchmy-schedulerPod lostmy-schedular (typo)kube-schedulerdefault-schedulerSecond schedulermy-schedulerNo schedulername not servednode-1runs webnode-2runs batchPendingno events, no node
One field decides which scheduler handles a Pod. Each scheduler only picks up Pods that carry a name it serves. A Pod with no schedulerName gets default-scheduler. A Pod that names a scheduler nobody serves waits for ever, with no events.

Parts:

  • Pod web (no schedulerName)
  • Pod batch (my-scheduler)
  • Pod lost (my-schedular (typo))
  • kube-scheduler (default-scheduler)
  • Second scheduler (my-scheduler)
  • No scheduler (name not served)
  • node-1 (runs web)
  • node-2 (runs batch)
  • Pending (no events, no node)

Connections:

  • Pod web to kube-scheduler: default
  • kube-scheduler to node-1: binds
  • Pod batch to Second scheduler: by name
  • Second scheduler to node-2: binds
  • Pod lost to No scheduler: no match
  • No scheduler to Pending: waits

Nothing registers a scheduler with the cluster. There is no Scheduler object, no list to add it to. A scheduler is just a program that:

  1. watches the API server for Pods with an empty spec.nodeName and a spec.schedulerName it serves,
  2. picks a node for each, and
  3. posts a Binding, which sets spec.nodeName.

The whole routing mechanism is therefore one string compare on one field:

Pod's spec.schedulerNameWho places it
Not setThe API server fills in default-scheduler, so the default kube-scheduler
default-schedulerThe default kube-scheduler
my-scheduler, and a scheduler serving that name runsThat scheduler
A name no running scheduler servesNobody. The Pod stays Pending, with no events

A few consequences follow from that design:

  • Names must be unique. If two schedulers answered to the same name, both would try to place the same Pods.
  • The field is fixed at creation. You cannot move a live Pod to another scheduler; recreate it. For a Deployment, DaemonSet or Job, set schedulerName in the Pod template (spec.template.spec.schedulerName), and the controller creates new Pods with it.
  • Everything not marked stays on the default. Adding a second scheduler changes nothing for existing workloads, system Pods or DaemonSets.
  • Static Pods and Pods with nodeName set never reach any scheduler, whatever schedulerName says.

How a second scheduler works

What a second scheduler is made ofcreatesmounted as --configruns asgrantswatchesConfigMapname, leader electionServiceAccountmy-schedulerClusterRoleBindingsystem:kube-schedulerDeploymentkube-systemScheduler Podkube-scheduler imageAPI serverPods, nodes, bindings
What a second scheduler is made of. A second scheduler is the same kube-scheduler binary, started with its own configuration file. As a Deployment it needs a ServiceAccount with the scheduler's permissions and a ConfigMap that holds the configuration.

Parts:

  • ConfigMap (name, leader election)
  • ServiceAccount (my-scheduler)
  • ClusterRoleBinding (system:kube-scheduler)
  • Deployment (kube-system)
  • Scheduler Pod (kube-scheduler image)
  • API server (Pods, nodes, bindings)

Connections:

  • Deployment to Scheduler Pod: creates
  • ConfigMap to Scheduler Pod: mounted as --config
  • ServiceAccount to Scheduler Pod: runs as
  • ClusterRoleBinding to ServiceAccount: grants
  • Scheduler Pod and API server: watches

In the exam, and in most clusters, a "second scheduler" is not new software. It is the same kube-scheduler binary, started a second time with a different configuration. Four things make it a separate scheduler:

WhatWhy it mattersWhere it is set
Its nameDecides which Pods it placesprofiles[].schedulerName in the configuration file
Its configuration fileCarries the name, the leader election settings and any plugin changesA KubeSchedulerConfiguration, passed with --config=<path>
Its identity and permissionsIt must read Pods and nodes and create Bindings and EventsA ServiceAccount bound to the system:kube-scheduler ClusterRole, or the kubeconfig /etc/kubernetes/scheduler.conf
Its leader election lockTwo different schedulers must not compete for one lockleaderElection in the configuration file

The smallest useful configuration file is six lines:

apiVersion: kubescheduler.config.k8s.io/v1
kind: KubeSchedulerConfiguration
profiles:
  - schedulerName: my-scheduler
leaderElection:
  leaderElect: false

Why leader election needs attention

Leader election exists for copies of the same scheduler: with three control plane nodes, three default schedulers run, and a Lease named kube-scheduler in kube-system makes sure only one is active.

A second scheduler is not a copy of the default one, so it must stay out of that election. If you start it with leader election on and the default lock name, it politely waits for a lock the default scheduler never gives up. It runs, it looks healthy, and it schedules nothing.

Your second scheduler runs asSet
One replicaleaderElect: false
Several replicasleaderElect: true, plus its own resourceName (for example my-scheduler) and resourceNamespace, and permission to use a Lease of that name
Under the hood · Leader election with several replicas of the second scheduler

With more than one replica, give the group its own lock:

leaderElection:
  leaderElect: true
  resourceNamespace: kube-system
  resourceName: my-scheduler

The built-in system:kube-scheduler ClusterRole only allows get and update on the Lease named kube-scheduler. For another lock name, add it to the rule's resourceNames (kubectl edit clusterrole system:kube-scheduler), or bind a small Role of your own that allows get, update and create on that Lease. Without it the scheduler logs leases.coordination.k8s.io "my-scheduler" is forbidden and never becomes leader.

Check who holds each lock with kubectl -n kube-system get lease.

Permissions

A scheduler that cannot list Pods or create Bindings does nothing useful. Run as a Deployment, it uses a ServiceAccount, and the documentation binds three things to it:

BindingGives
ClusterRoleBinding to system:kube-schedulerEverything the built-in scheduler may do: watch Pods and nodes, create Bindings and Events
ClusterRoleBinding to system:volume-schedulerReading and updating PersistentVolumes, claims and StorageClasses, for Pods with volumes
RoleBinding in kube-system to extension-apiserver-authentication-readerReading the API server's authentication settings, for its own HTTPS endpoint

Run as a static Pod on a kubeadm control plane node, it can reuse /etc/kubernetes/scheduler.conf, which already signs in as system:kube-scheduler, so no extra RBAC is needed.

Two ways to run it

As a DeploymentAs a static Pod
Where it is definedObjects in kube-system: ServiceAccount, bindings, ConfigMap, DeploymentA manifest in /etc/kubernetes/manifests plus a config file on the control plane node
Who starts itThe default scheduler places its Pod, the kubelet runs itThe kubelet alone
CredentialsServiceAccount token/etc/kubernetes/scheduler.conf
Port 10259Free: the Pod has its own network namespaceTaken by the default scheduler on the host network; pick another --secure-port
Good forThe documented way, works on any clusterkubeadm clusters, and the usual exam shortcut: copy the default manifest

Separate schedulers do not coordinate

Separate schedulers do not see each other's planspendingpendingbinds webbinds batchPod webrequests 1 CPUPod batchrequests 1 CPUdefault-schedulersees 1 CPU freemy-schedulersees 1 CPU freenode-11 CPU unreserved
Separate schedulers do not see each other's plans. Each scheduler process keeps its own picture of free capacity. Two of them can promise the same free CPU to two Pods; the kubelet then rejects the Pod that arrives second. Give each scheduler its own set of nodes.

Parts:

  • Pod web (requests 1 CPU)
  • Pod batch (requests 1 CPU)
  • default-scheduler (sees 1 CPU free)
  • my-scheduler (sees 1 CPU free)
  • node-1 (1 CPU unreserved)

Connections:

  • Pod web to default-scheduler: pending
  • Pod batch to my-scheduler: pending
  • default-scheduler to node-1: binds web
  • my-scheduler to node-1: binds batch

Each scheduler process keeps its own cache of what is free on every node. Inside one process that cache is updated the moment a Pod is assigned, so two Pods are never promised the same space. Between separate processes there is no such protection: two schedulers can look at the same node at the same moment, both see room for one more Pod, and both bind there.

The node is the last line of defence. The kubelet checks every Pod it is handed against what it really has, and rejects the one that does not fit: the Pod fails with a status such as OutOfcpu or OutOfmemory. A controller then creates a replacement; a bare Pod stays failed.

Two ways to avoid this:

  • Give each scheduler its own nodes. Label a node pool and make the Pods of each scheduler target it with nodeSelector or node affinity (plus a taint to keep others out).
  • Use profiles in one scheduler instead. A single kube-scheduler can serve several names from one process, with one shared cache and queue, so it cannot contradict itself. That is the subject of the next lesson, Configuring Scheduler Profiles, and it is the better choice when all you need is different plugin settings.

Using it

Example · Deploy a second scheduler as a Deployment

This is the manifest from the documentation page Configure Multiple Schedulers, shortened to the parts that matter. It uses the same image as the default scheduler; read the tag from the running one:

kubectl -n kube-system get pod -l component=kube-scheduler \
  -o jsonpath='{.items[0].spec.containers[0].image}{"\n"}'
apiVersion: v1
kind: ServiceAccount
metadata:
  name: my-scheduler
  namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: my-scheduler-as-kube-scheduler
subjects:
  - kind: ServiceAccount
    name: my-scheduler
    namespace: kube-system
roleRef:
  kind: ClusterRole
  name: system:kube-scheduler
  apiGroup: rbac.authorization.k8s.io
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: my-scheduler-as-volume-scheduler
subjects:
  - kind: ServiceAccount
    name: my-scheduler
    namespace: kube-system
roleRef:
  kind: ClusterRole
  name: system:volume-scheduler
  apiGroup: rbac.authorization.k8s.io
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: my-scheduler-extension-apiserver-authentication-reader
  namespace: kube-system
subjects:
  - kind: ServiceAccount
    name: my-scheduler
    namespace: kube-system
roleRef:
  kind: Role
  name: extension-apiserver-authentication-reader
  apiGroup: rbac.authorization.k8s.io
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: my-scheduler-config
  namespace: kube-system
data:
  my-scheduler-config.yaml: |
    apiVersion: kubescheduler.config.k8s.io/v1
    kind: KubeSchedulerConfiguration
    profiles:
      - schedulerName: my-scheduler
    leaderElection:
      leaderElect: false
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: my-scheduler
  namespace: kube-system
  labels:
    component: scheduler
spec:
  replicas: 1
  selector:
    matchLabels:
      component: scheduler
  template:
    metadata:
      labels:
        component: scheduler
    spec:
      serviceAccountName: my-scheduler
      containers:
        - name: kube-second-scheduler
          image: registry.k8s.io/kube-scheduler:v1.37.0
          command:
            - kube-scheduler
            - --config=/etc/kubernetes/my-scheduler/my-scheduler-config.yaml
          livenessProbe:
            httpGet: { path: /healthz, port: 10259, scheme: HTTPS }
            initialDelaySeconds: 15
          readinessProbe:
            httpGet: { path: /healthz, port: 10259, scheme: HTTPS }
          volumeMounts:
            - name: config-volume
              mountPath: /etc/kubernetes/my-scheduler
      volumes:
        - name: config-volume
          configMap:
            name: my-scheduler-config
kubectl apply -f my-scheduler.yaml
kubectl -n kube-system rollout status deploy/my-scheduler
kubectl -n kube-system logs deploy/my-scheduler | tail -n 5

The mount path, the file name (the ConfigMap key) and the --config value must agree. That is the most common mistake when typing this by hand.

Example · Run it as a static Pod on a kubeadm control plane

Faster in the exam when you are already on the control plane node: start from the default scheduler's manifest. Write the configuration file first, then the manifest, so the Pod does not start without its file:

ssh controlplane
sudo tee /etc/kubernetes/my-scheduler-config.yaml <<'EOF'
apiVersion: kubescheduler.config.k8s.io/v1
kind: KubeSchedulerConfiguration
clientConnection:
  kubeconfig: /etc/kubernetes/scheduler.conf
profiles:
  - schedulerName: my-scheduler
leaderElection:
  leaderElect: false
EOF
sudo cp /etc/kubernetes/manifests/kube-scheduler.yaml /root/my-scheduler.yaml   # edit the copy outside the folder
sudo vi /root/my-scheduler.yaml

Change these things in the copy, and nothing else:

metadata:
  name: my-scheduler                       # 1. a new Pod name
spec:
  containers:
    - name: my-scheduler
      command:
        - kube-scheduler
        - --config=/etc/kubernetes/my-scheduler-config.yaml   # 2. add the config file
        - --secure-port=10282                                  # 3. a free port; 10259 is taken
        # 4. remove the line --leader-elect=true, the config file decides now
        # keep the --kubeconfig, --authentication-kubeconfig and --authorization-kubeconfig lines
      volumeMounts:
        - name: my-config                  # 5. mount the config file
          mountPath: /etc/kubernetes/my-scheduler-config.yaml
          readOnly: true
  volumes:
    - name: my-config
      hostPath:
        path: /etc/kubernetes/my-scheduler-config.yaml
        type: File

Also change every 10259 in the probes (and in ports, if the manifest has that block) to 10282, otherwise the kubelet probes the default scheduler's port and the result tells you nothing about yours. Then put the file in place:

sudo cp /root/my-scheduler.yaml /etc/kubernetes/manifests/my-scheduler.yaml
kubectl -n kube-system get pods | grep scheduler
kube-scheduler-controlplane   1/1   Running   0   41d
my-scheduler-controlplane     1/1   Running   0   20s

If the new Pod does not appear, the kubelet could not read the manifest: sudo journalctl -u kubelet --since "2 min ago" | grep -i my-scheduler. If it appears but crashes, sudo crictl ps -a --name my-scheduler and sudo crictl logs <container-id>.

Example · Send a Pod to it, and prove it

kubectl run batch --image=busybox:1.37 --dry-run=client -o yaml --command -- sleep 3600 > batch.yaml

Add one line under spec:

apiVersion: v1
kind: Pod
metadata:
  name: batch
spec:
  schedulerName: my-scheduler
  containers:
    - name: batch
      image: busybox:1.37
      command: ["sleep", "3600"]
kubectl apply -f batch.yaml
kubectl get pod batch -o wide                       # it has a node
kubectl describe pod batch | grep -A 3 Events
Events:
  Type    Reason     Age   From          Message
  Normal  Scheduled  8s    my-scheduler  Successfully assigned default/batch to node-2

The From column is the proof. For a Pod placed by the default scheduler it reads default-scheduler. The same across the cluster, as a table:

kubectl get events -A --field-selector reason=Scheduled \
  -o custom-columns=POD:.involvedObject.name,BY:.reportingComponent,MESSAGE:.message

For a Deployment the field goes into the Pod template, and changing it starts a normal rolling update:

kubectl patch deployment report --type merge \
  -p '{"spec":{"template":{"spec":{"schedulerName":"my-scheduler"}}}}'

Example · A Pod for the second scheduler stays Pending

kubectl describe pod batch | tail -n 3              # Events: <none>

No events means no scheduler touched the Pod. Work through the chain, from the Pod to the scheduler:

# 1. Which name does the Pod ask for? Look for typos.
kubectl get pod batch -o jsonpath='{.spec.schedulerName}{"\n"}'

# 2. Is a scheduler running for that name?
kubectl -n kube-system get pods | grep scheduler

# 3. Which name does that scheduler serve?
kubectl -n kube-system get configmap my-scheduler-config -o yaml | grep schedulerName
#    static Pod: sudo grep schedulerName /etc/kubernetes/my-scheduler-config.yaml

# 4. Is it really scheduling, or waiting or forbidden?
kubectl -n kube-system logs deploy/my-scheduler | tail -n 20

What the logs tell you:

In the logsCauseFix
unknown flag: --scheduler-nameA removed flagPut the name in the config file
strict decoding error: unknown fieldA typo in the config fileFix the field name; restart the Pod
attempting to acquire leader lease kube-system/kube-scheduler... and nothing afterWaiting for the default scheduler's lockleaderElect: false, or its own resourceName
is forbidden: User "system:serviceaccount:kube-system:my-scheduler" cannot listMissing RBACBind the ServiceAccount to system:kube-scheduler
bind: address already in usePort 10259 on the host networkAnother --secure-port

A changed ConfigMap is not picked up by a running scheduler: kubectl -n kube-system rollout restart deploy/my-scheduler. A wrong name in the Pod cannot be edited: fix the file and kubectl replace --force -f batch.yaml. Once a scheduler serves the name, the waiting Pod is placed within seconds without any other action.

Tricks

Common mistakes

  • Leaving leader election on with the default lock. The second scheduler runs and is Ready, but waits for the kube-scheduler Lease for ever. Pods that name it stay Pending with no events.
  • A name that differs by one character. my-scheduler in the config and myscheduler in the Pod do not match, and nothing reports the mismatch.
  • Putting schedulerName in the wrong place. It belongs under the Pod's spec. In a Deployment that is spec.template.spec, not the Deployment's own spec.
  • Editing schedulerName on a running Pod. The API server refuses the change. Recreate the Pod, or change the template of the controller that owns it.
  • Reusing port 10259 for a static Pod scheduler. Both schedulers use the host network there, so the second one fails to start, or its probes silently check the first one.
  • Expecting a fallback. If the second scheduler is deleted or broken, its Pods are not taken over by default-scheduler. New Pods wait; Pods already running are not affected, because a scheduler is only needed once.
  • Letting two schedulers share nodes without thinking. They can overcommit a node between them. Separate their nodes, or use profiles in one scheduler.

Recap

  • Any number of schedulers can run; each has a unique name and places only the Pods that ask for it.
  • spec.schedulerName chooses the scheduler. Unset means default-scheduler. It is fixed when the Pod is created.
  • A second scheduler is the kube-scheduler binary with its own KubeSchedulerConfiguration (--config): its name under profiles, and leader election off or on its own lock.
  • It needs the permissions of system:kube-scheduler, through a ServiceAccount or scheduler.conf.
  • Pending with no events: check the name in the Pod, then whether a scheduler serving it runs and is really active.
  • The From column of the Scheduled event tells you which scheduler placed a Pod.

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.

Practise: try it on a real cluster

A hands-on lab for this lesson. You get goals, not steps: any solution that reaches them passes.

  • Run a second kube-scheduler next to the default one, hand it one team's workload, and repair a pod that asks for a scheduler nobody runs.

    Build · Level 3 · challenge · target 25 min

Discussion

Learners ask and answer questions here. Sign in to read and join the discussion.