QA
Senior LevelDocker & Deployment

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):

1
PreFilter: Preprocess pod information / check cluster-wide conditions.
2
Filter: Filter out nodes that cannot run the pod (replaces old Predicates). Any plugin returning Unschedulable eliminates the node.
3
PostFilter: Called when no nodes pass Filter — implement preemption logic here.
4
PreScore: Prepare state for Scoring.
5
Score: Assign each feasible node a score (0–100). Higher = more preferred (replaces old Priorities).
6
Reserve: Reserve resources on the chosen node (optimistic locking).
7
Permit: Allow, Deny, or Wait (for gang scheduling patterns).

Binding Cycle (async):

8
PreBind: Mount volumes, set up network.
9
Bind: Assign the pod to the node (write to API server).
10
PostBind: Cleanup / metrics emission.

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

typescript
// 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 scheduler
💡Custom Score plugin prefers nodes with most free GPU memory — Framework handles the rest of scheduling logic.
🎯 Interview Key Takeaway

Kubernetes 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.

#Kubernetes#Custom Scheduler#Scheduling Framework#Plugin#GPU Scheduling#Senior
Back to all Docker & Deployment Questions→

More Docker & Deployment Interview Questions

Beginner LevelDocker & Deployment

How do Docker Multi-Stage Builds minimize image size and improve security?

Beginner LevelDocker & Deployment

What is the difference between a Docker Container and a Virtual Machine (VM)?

Beginner LevelDocker & Deployment

What is the difference between a Docker Image and a Docker Container?