Skip to main content
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.

Default Scheduler Configuration

A configuration file for the default scheduler might look like this:

Creating a Custom Scheduler

To create a custom scheduler, prepare a separate configuration file that specifies a unique scheduler name. For example:

Deploying an Additional Scheduler as a Service

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.

Default Scheduler Service

Custom Scheduler Service

Create a service file for your custom scheduler, for example, my-scheduler-2.service:
And the corresponding configuration file:
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.

Deploying a Scheduler as a Pod

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:
The custom scheduler configuration file might look as follows:

Leader Election for High Availability

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:
And the corresponding configuration file:
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.

Deploying a Scheduler as a Deployment

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.

Building a Custom Scheduler Image

Clone the Kubernetes repository and build your scheduler:
Then create a Dockerfile that includes the scheduler binary:
Build and push your Docker image:

RBAC Setup for the Custom Scheduler

For secure deployment, create a ServiceAccount and bind the necessary ClusterRoles. Here’s an example configuration:

Deployment Manifest Example

Below is a sample Deployment manifest for your custom scheduler. This deployment uses a ConfigMap to mount the custom configuration file as a volume:
A corresponding ConfigMap that contains the scheduler configuration is as follows:
For enhanced security, ensure your RBAC resources are correctly configured. Below is an example of a ClusterRole setup:
When you run:
You should see your custom scheduler pod or Deployment along with the other control plane components.

Using the Custom Scheduler for Pods

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:
Deploy the pod with:
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:
A typical events output might be:
LAST SEENCOUNTNAMEKINDTYPEREASONSOURCEMESSAGE
9s1nginx.15PodNormalScheduledmy-custom-schedulerSuccessfully assigned default/nginx to node01
8s1nginx.15PodNormalPullingkubelet, node01pulling image “nginx”
2s1nginx.15PodNormalPulledkubelet, node01Successfully pulled image “nginx”
2s1nginx.15PodNormalCreatedkubelet, node01Created container
2s1nginx.15PodNormalStartedkubelet, node01Started 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.

Conclusion

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.

Watch Video