How do you build a Custom Kubernetes Scheduler using the Scheduling Framework API?
❓ Interview Prompt: Explain the Kubernetes Scheduling Framework extension points (Filter, Score, Reserve, Permit), plugin compilation, and use cases for custom pod placement logic.
The Kubernetes Scheduling Framework provides a plugin-based architecture for customizing pod scheduling behavior without forking the scheduler binary.
Scheduling Cycle Extension Points:
Each pod goes through two cycles:
Scheduling Cycle (serial, per-pod):
Unschedulable eliminates the node.Binding Cycle (async):
Plugin Implementation:
Custom plugins implement the relevant interfaces from k8s.io/kubernetes/pkg/scheduler/framework. Compiled into the scheduler binary or run as a separate scheduler named via schedulerName in pod spec.
Code Implementation Example
// Custom Score plugin: prefer nodes with lowest GPU memory usage
// (conceptual — actual implementation is Go)
// Go equivalent (simplified pseudocode in TypeScript for clarity):
class GPUMemoryScorePlugin implements ScorePlugin {
name = "GPUMemoryScore";
// Called for each feasible node
score(pod: Pod, node: Node): [score: number, status: Status] {
const gpuMemoryFree = node.labels["gpu-memory-free-gb"];
if (!gpuMemoryFree) {
return [0, Status.Success]; // no GPU info = neutral score
}
// Score 0-100: more free GPU memory = higher score
const freeGB = parseInt(gpuMemoryFree);
const score = Math.min(100, freeGB * 5); // 20GB free = score 100
return [score, Status.Success];
}
// Normalize scores across all nodes to 0-100 range
normalizeScore(scores: Map<string, number>): void {
const maxScore = Math.max(...scores.values());
for (const [node, score] of scores) {
scores.set(node, (score / maxScore) * 100);
}
}
}
// Pod using custom scheduler:
// spec:
// schedulerName: gpu-scheduler # route to custom schedulerKubernetes Scheduling Framework provides Filter (feasibility), Score (preference), and Reserve/Permit (binding) extension points. Compile custom plugins for advanced placement: GPU topology, latency-aware, batch gang scheduling.