This article covers deploying multiple schedulers in Kubernetes to enable custom placement logic for specific applications while using the default scheduler for most workloads.
Welcome to this article on deploying multiple schedulers in a Kubernetes cluster. In this guide, we will walk through configuring and deploying additional schedulers—enabling you to use custom placement logic for specific applications while still relying on the default scheduler for most workloads.Kubernetes distributes pods evenly across nodes and considers factors such as taints, tolerations, and node affinity when using its default scheduler. However, if your application requires custom scheduling behavior, Kubernetes allows you to implement and deploy a custom scheduler alongside the default one. When running multiple schedulers, each must have a unique name so Kubernetes can easily differentiate between them. The default scheduler is typically named “default-scheduler”.
Even though you do not need an explicit configuration file for the default scheduler, creating one can help you document and customize the scheduling behavior if needed.
When deploying an extra scheduler as a service, you typically use the same kube-scheduler binary or a modified version with a unique configuration file. Below are two examples—one for the default scheduler and another for a custom scheduler.
Each scheduler reads its configuration file—which includes its unique schedulerName—along with any additional options like the kubeconfig file necessary for connecting to the Kubernetes API.
Another common approach is deploying the scheduler as a pod. In this setup, define a pod manifest that points to the custom kube-scheduler configuration file. Below is an example of a basic pod definition:
When running multiple instances of the same scheduler (such as on different master nodes), enable leader election to ensure only one instance is active at a time. The following pod manifest and configuration file enable leader election:Pod manifest with leader election enabled:
This configuration differentiates your custom scheduler’s leader election mechanism from that of the default scheduler, ensuring seamless high availability in a multi-master setup.
In many Kubernetes environments, control plane components are deployed as pods or Deployments using kubeadm. You can also deploy your custom scheduler in this manner by building a custom Docker image.
Once your custom scheduler is deployed, you can instruct specific pods to use it by setting the schedulerName field in their manifests. For example, here is a pod manifest for an nginx pod using the custom scheduler:
If the custom scheduler is not configured correctly, the pod will remain in a pending state. Use the following commands to inspect pod events and troubleshoot:
Copy
Ask AI
kubectl describe pod nginxkubectl get events -o wide
A typical events output might be:
LAST SEEN
COUNT
NAME
KIND
TYPE
REASON
SOURCE
MESSAGE
9s
1
nginx.15
Pod
Normal
Scheduled
my-custom-scheduler
Successfully assigned default/nginx to node01
8s
1
nginx.15
Pod
Normal
Pulling
kubelet, node01
pulling image “nginx”
2s
1
nginx.15
Pod
Normal
Pulled
kubelet, node01
Successfully pulled image “nginx”
2s
1
nginx.15
Pod
Normal
Created
kubelet, node01
Created container
2s
1
nginx.15
Pod
Normal
Started
kubelet, node01
Started container
The event source confirms that the custom scheduler successfully handled pod scheduling.
To troubleshoot your custom scheduler, view its logs with:kubectl logs my-custom-scheduler —namespace=kube-systemReviewing these logs will help pinpoint configuration errors or leader election issues.
Deploying multiple schedulers in a Kubernetes cluster allows you to implement tailored scheduling strategies for different workloads while leaving the default scheduler in place. This guide outlined the configurations and deployment methods—ranging from running the scheduler as a service or pod to deploying it as a Deployment with proper RBAC and leader election setups.Happy scheduling!For more information on Kubernetes scheduling, visit the Kubernetes Documentation and explore additional resources on Custom Schedulers.