✦ For everyone, free.

Practical knowledge for real and everyday life

Home

15 Kubernetes Scheduling and Placement

Kubernetes Scheduling and Placement ensures efficient resource allocation by automatically placing workloads across nodes based on defined policies and constraints.

Kubernetes Scheduling and Placement is the process by which the scheduler decides which node a newly created Pod should run on, weighing resource availability, constraints, and preferences to select a node that satisfies the Pod's requirements while making efficient use of the cluster's overall capacity.


The Scheduling Problem

What the Scheduler Solves

Scheduling assigns Pods that have not yet been bound to a node to one of the available nodes in the cluster. This decision must respect hard requirements, such as a Pod needing more memory than a node has free, while also weighing softer preferences, such as spreading replicas across failure domains.

Two-Phase Process

Kubernetes scheduling proceeds in two conceptual phases: filtering, which eliminates nodes that cannot satisfy a Pod's requirements at all, and scoring, which ranks the remaining feasible nodes to select the most suitable one.

selectedNode = argmax nfeasible score(n)

Filtering Criteria

Resource Requirements

A node is filtered out if it does not have enough allocatable CPU, memory, or other declared resources to satisfy a Pod's resource requests, since scheduling a Pod onto an overcommitted node would risk it being evicted or throttled.

Taints and Tolerations

Nodes can be tainted to repel Pods that do not explicitly tolerate that taint, which is used to reserve nodes for specific purposes, such as excluding regular workloads from control plane nodes unless they declare the matching toleration.

Node Selectors and Affinity

A Pod can specify node selectors or node affinity rules that require or prefer scheduling onto nodes with particular labels, such as a specific hardware type or availability zone.


Scoring Criteria

Resource Balancing

Among nodes that pass filtering, the scheduler favors those that would leave a more balanced distribution of resource utilization across the cluster, avoiding concentrating load onto a small number of nodes while others remain underutilized.

Pod Affinity and Anti-Affinity

Pod affinity rules allow a Pod to prefer being scheduled near Pods with certain labels, useful for co-locating cooperating services, while anti-affinity rules favor spreading Pods apart, commonly used to avoid placing all replicas of a critical service on the same node or availability zone.

Topology Spread Constraints

Topology spread constraints explicitly control how evenly Pods belonging to the same workload should be distributed across defined topology domains, such as zones or nodes, improving resilience to the failure of any single domain.


Advanced Scheduling Mechanisms

Priority and Preemption

Pods can be assigned a priority class, and if a high-priority Pod cannot be scheduled due to insufficient resources, the scheduler may preempt, or evict, lower-priority Pods to make room, ensuring critical workloads are scheduled even under resource pressure.

Custom Schedulers

Kubernetes allows multiple schedulers to run simultaneously, and Pods can specify which scheduler should be responsible for placing them, enabling specialized scheduling logic for workloads with requirements not covered by the default scheduler.


Scheduling Flow Diagram

Pending Pod Filter Score

Together, these filtering and scoring mechanisms allow the scheduler to make placement decisions that satisfy hard constraints while optimizing for resilience and efficient resource use across the cluster as a whole.