Skip to main content

Custom Schedulers

Key Takeaways for AI & Readers
  • Extensible Scheduling: Kubernetes allows running custom schedulers alongside the default one, enabling specialized workload placement logic.
  • Scheduling Cycle: A scheduler's core function involves queuing, filtering eligible nodes, scoring them based on criteria, and binding Pods to the best-fit node.
  • Advanced Optimization: Custom schedulers are used for niche requirements like cost-aware placement, ensuring data locality, or optimizing for specific hardware topologies (e.g., GPU interconnections).
  • Flexibility: By extending the scheduling process, complex operational requirements can be directly integrated into Kubernetes.

Kubernetes comes with a high-quality "Default Scheduler", but it isn't perfect for every use case. If you have complex workloads (like high-performance computing or specific gaming requirements), you can write your own scheduler.

1. Using Multiple Schedulers

You can run your own scheduler side-by-side with the default one. You choose which one to use in the Pod spec.

apiVersion: v1
kind: Pod
metadata:
name: expensive-app
spec:
schedulerName: default-scheduler
➡️
⚖️
Standard Logic
You can run multiple schedulers in one cluster. By setting schedulerName, you tell Kubernetes to ignore the default scheduler and use your custom logic instead.

2. The Scheduling Cycle

A scheduler has one job: Watch the API Server for Pods where nodeName is empty, and fill it in.

The logic happens in stages:

  1. Queueing: Sort pods by priority.
  2. Filtering: Remove nodes that don't have enough resources.
  3. Scoring: Rank the remaining nodes (e.g. "Which node has the least power usage?").
  4. Binding: Send the result back to the API Server.

3. Why write one?

  • Cos-Aware Scheduling: Minimize cloud costs by packing pods onto the cheapest nodes.
  • Data Locality: Schedule pods on nodes that physically hold the data they need.
  • GPU Topology: Ensure multi-GPU pods land on nodes where the GPUs are connected by high-speed NVLink.