DevOps & Kubernetes (50 Qs)•Part 2: Kubernetes Architecture & Core Workloads (11 - 25)
Kube-Scheduler Deep-Dive: How Filtering, Scoring, Node Affinity, Taints, and Tolerations place Pods.
Scheduling Pipeline & Algorithms
When a Pod is submitted with spec.nodeName == "", the kube-scheduler selects the best node in two primary phases: Filtering (Predicates) and Scoring (Priorities).
scss
[ Unschedulable Pod ]
|
v
+---------------------------------------------------+
| 1. Filtering Phase (Predicates) |
| - NodeResourcesFit (CPU, RAM available) |
| - NodeName matches (if specified) |
| - PodFitsHostPorts |
| - NodeAffinity & NodeSelector |
| - Taints & Tolerations matching |
| - PodTopologySpreadConstraints |
+---------------------------------------------------+
| (List of Feasible Candidate Nodes)
v
+---------------------------------------------------+
| 2. Scoring Phase (Priorities) |
| - LeastAllocated (Balance load) |
| - MostAllocated (Bin-packing for cost saving) |
| - ImageLocalityPriority (Image already cached) |
| - InterPodAffinityPriority |
+---------------------------------------------------+
| (Highest Scoring Node)
v
[ Bind Pod to Node via API Server ]
Taints vs. Tolerations vs. Node Affinity
| Mechanism | Where it is set | Purpose | Rule Syntax |
|---|---|---|---|
| Taint | On the Node | Repels Pods from being scheduled unless the Pod tolerates the taint. | kubectl taint nodes node-1 dedicated=gpu:NoSchedule |
| Toleration | In the Pod spec | Allows (but does not force) a Pod to schedule onto a tainted node. | tolerations: [{key: "dedicated", value: "gpu", effect: "NoSchedule"}] |
| Node Affinity | In the Pod spec | Attracts a Pod to specific nodes based on node labels. | requiredDuringSchedulingIgnoredDuringExecution (hard) vs preferredDuringScheduling... (soft) |
Production Topology Spread Example
Ensures Pod replicas are distributed evenly across Availability Zones:
yaml
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels:
app: payment-api