Pod scheduling
The scheduler assigns pods to nodes according to resource availability and placement rules. Its behavior can be extended with plugins and placement settings in Deckhouse Platform.
General overview of the scheduler
The scheduler is a component responsible for assigning pods to cluster nodes based on available resources and specified rules. It selects the most suitable node for running each pod, considering many factors such as CPU and memory availability, data locality, network topology, node labels, and application-specific requirements.
The scheduler operates in multiple stages, each involving different plugins. These plugins evaluate nodes against specific criteria and help determine the optimal placement for a pod.
Main tasks of the scheduler:
- Filtering — determines which nodes meet the pod’s requirements.
- Scoring — assigns scores to nodes based on various criteria (the higher the score, the better the node).
- Binding — assigns the pod to the best node based on scoring results.
Plugins may participate in one or multiple stages. For example, one plugin might be used only during filtering, while another can be involved in both filtering and scoring.
Examples of plugins:
-
ImageLocality (phase: Scoring) — prefers nodes that already have the required container images. This helps reduce deployment time since images do not need to be pulled from a remote repository.
-
TaintToleration (phases: Filtering, Scoring) — implements the taints and tolerations mechanism. It helps avoid placing pods on unsuitable nodes or, conversely, forces placement on specific nodes (e.g., those with dedicated resources).
-
NodePorts (phase: Filtering) — checks if the node has free ports required by the pod. This is especially important for services using fixed NodePorts, as a node cannot host multiple pods using the same port.
For the complete list of plugins, refer to the Kubernetes documentation.
Pod scheduling phases
The process of assigning pods to nodes in Deckhouse Platform involves several key phases. The scheduler analyzes available nodes, applies various filtering and scoring criteria, and then selects the most suitable node to run the pod.
In the Filtering phase, filtering plugins are activated. These plugins evaluate all available nodes and select only those that meet certain conditions (e.g., taints, nodePorts, nodeName, unschedulable, and others).
If the nodes are distributed across different availability zones, Deckhouse Platform alternates between zones during selection to avoid placing all pods in a single zone. For example, if the nodes are distributed like this:
Zone 1: Node 1, Node 2, Node 3, Node 4
Zone 2: Node 5, Node 6
The selection will occur in the following order:
Node 1, Node 5, Node 2, Node 6, Node 3, Node 4
It is important to note that the scheduler does not evaluate all nodes in the cluster — only a subset is considered to optimize the scheduling process. The number of nodes evaluated depends on the size of the cluster:
- In small clusters (≤50 nodes), all nodes are evaluated.
- In medium clusters (~100 nodes), about 50% of nodes are evaluated.
- In very large clusters (~5000 nodes), only 10% of nodes are evaluated.
- The minimum threshold is 5% of nodes when there are more than 5000.
After the filtering phase, the scoring phase begins. During this stage, each node from the filtered list is scored by various scoring plugins that analyze its characteristics and how well it matches the pod’s requirements.
Each plugin evaluates a node based on its specific criteria and assigns it a score. These scores are then aggregated to produce an overall ranking.
Key factors considered during scoring include:
- Node load (
pod capacity) — available CPU and memory are taken into account. Nodes with more free resources receive higher scores. - Container image locality (ImageLocality) — nodes that already have the required container images are preferred, as this speeds up pod deployment.
- Affinity and anti-affinity rules — nodes that satisfy required placement (or avoidance) rules based on other pods get higher priority.
- Storage availability (
volume provisioning) — nodes with the necessary PersistentVolumes receive a higher score.
After all scores are summed, the node with the highest total score is selected for pod placement.
If multiple nodes receive the same highest score, the selection is made randomly to avoid inefficient and predictable load distribution.
How to modify or extend scheduler logic
The scheduler in Deckhouse Platform can be flexibly configured and extended using custom plugins. This allows its behavior to be adapted to specific cluster requirements, such as considering custom metrics, special workload distribution rules, or node prioritization.
Each such plugin is implemented as a webhook and must meet the following requirements:
- TLS usage: The plugin must be accessed over a secure TLS connection.
- Availability: The plugin must be deployed as a service inside the cluster and accessible via HTTP(S).
- Support for standard verbs: The plugin must support standard scheduler operations:
filterVerb = filter: Participates in node filtering before pod placement.prioritizeVerb = prioritize: Participates in node scoring during the Scoring phase.
- Node cache capability: It is expected that all extender plugins support caching node data (
nodeCacheCapable: true) to improve performance.
To connect an extender plugin, use the KubeSchedulerWebhookConfiguration resource. This resource defines the configuration for an external webhook used by the kube-scheduler and enables more advanced scheduling conditions in the cluster, such as:
- Placing application pods closer to data storage nodes
- Prioritizing nodes based on their current state (e.g., network load or storage subsystem health)
- Segmenting nodes into zones
Example of connecting an external scheduler plugin via webhook:
apiVersion: deckhouse.io/v1alpha1
kind: KubeSchedulerWebhookConfiguration
metadata:
name: sds-replicated-volume
webhooks:
- weight: 5
failurePolicy: Ignore
clientConfig:
service:
name: scheduler
namespace: d8-sds-replicated-volume
port: 8080
path: /scheduler
caBundle: ABCD=
timeout: 5s
If the failurePolicy: Fail parameter is used, any failure in the webhook will cause the scheduler to stop functioning entirely, preventing new pods from being scheduled. Thoroughly test custom scheduler plugins before deploying them in a production environment.
Additional pod placement mechanisms
Deckhouse Platform provides flexible mechanisms for managing pod placement within a cluster. These mechanisms help optimize load balancing, improve fault tolerance, and separate system and user workloads.
Main placement configuration options:
-
Using node labels (
NodeGroup.spec.nodeTemplate.labels).
Allows explicitly targeting specific nodes for pods usingspec.nodeSelectororspec.affinity.nodeAffinity. -
Configuring taints and tolerations.
Enables limiting pod scheduling to specific nodes, preventing them from being placed on unsuitable nodes. -
Using custom toleration keys (
settings.modules.placement.customTolerationKeys).
Allows control over the scheduling of critical Deckhouse components (e.g., CNI and CSI) on dedicated nodes.
-
Using
nodeSelector— allows you to explicitly specify which nodes pods should be scheduled on. This is done by labeling the desired nodes and referencing those labels in the pod’sspec.nodeSelector. Example:Suppose you have a node named
kube-system-1that is intended for monitoring services. Label the node:d8 k label node kube-system-1 node-role/monitoring=""Now, to deploy pods only on this node, add a
nodeSelectorto the Deployment:nodeSelector: node-role/monitoring: "" -
Using taints and tolerations — unlike
nodeSelector, taints are used to prevent pods from being scheduled on a node unless they have a matching toleration. This ensures that only specific services run on a given node. Example:Suppose you have a node named
kube-frontend-1that is dedicated exclusively to Ingress controllers. Apply a taint to the node:d8 k taint node kube-frontend-1 node-role/frontend="":NoExecuteNow, only pods with the appropriate toleration will be allowed to run on this node:
tolerations: - effect: NoExecute key: node-role/frontendThis mechanism prevents unintended pods from being scheduled on nodes that are meant for specific purposes.
-
Using
customTolerationKeys— Deckhouse supports thecustomTolerationKeysmechanism, which explicitly defines allowed toleration keys. This is useful when you need to run system services (such as CNI, CSI, etc.) on specific nodes. Example:customTolerationKeys: - dedicated.example.com - node-dedicated.example.com/masterThis mechanism allows:
- Divide nodes into zones — for example, dedicating some for Ingress controllers and others for system services (Prometheus, VPN, CoreDNS).
- Isolate critical applications from system components, avoiding resource contention.
Scheduler profiles
The scheduler supports multiple profiles that define different strategies for distributing pods across nodes in the cluster. Depending on the selected profile, pods will be scheduled with different load balancing logic.
default-scheduler— the default profile that attempts to evenly distribute pods across nodes, preferring less loaded ones.high-node-utilization— a profile that places pods on more heavily loaded nodes. This can be useful in scenarios where workload consolidation is needed, allowing underutilized nodes to be shut down or repurposed.
To select a scheduler profile, specify it in the spec.schedulerName field of the Pod manifest. Example:
apiVersion: v1
kind: Pod
metadata:
name: scheduler-example
labels:
name: scheduler-example
spec:
schedulerName: high-node-utilization
containers:
- name: example-pod
image: registry.k8s.io/pause:2.0
Pod redistribution
The Deckhouse Platform can redistribute pods across nodes after the state of the cluster changes. At a specified interval, it evicts pods that meet the criteria of active strategies, and the scheduler places new pods based on the cluster’s current state. For example, Deckhouse Platform can move pods from overloaded nodes, consolidate pods onto fewer nodes before the cluster is scaled down, and return those pods that once again meet their affinity rules.
To use pod redistribution, enable the descheduler module and create a Descheduler object with the required strategies.
The module settings are optional: the module works with the default values.
Creating a Descheduler
A Descheduler object sets the strategies and the pods and nodes they apply to. Several Descheduler objects can exist in the cluster, and each of them works independently. The examples on this page are Descheduler manifests: create an object from any of them in one of the following ways.
- Web UI
- CLI
- Go to System → System Management → Cluster → Scheduling → Deschedulers.
- Click Create.
- Enter the object name in the Name field.
- On the Configuration tab, in the Strategies block, enable the required strategies and set their thresholds. To set the parameters that the form does not show, or to use a manifest from the examples on this page, go to the YAML tab and edit the manifest.
- Click Apply.
The created object appears in the list of the Deschedulers section.
Save the manifest of a Descheduler object to the descheduler.yaml file and apply it:
d8 k apply -f descheduler.yaml
To check the created objects, run the following command:
d8 k get deschedulers
Module settings
The module settings set how often the module checks the cluster and how much detail it writes to the log:
deschedulingInterval: Interval between redistribution cycles.Frequentruns a cycle every 5 minutes,Moderateevery 15 minutes,Rareevery 30 minutes. The interval sets how often the cluster is checked, but does not guarantee an eviction in every cycle.logLevel: Logging level of the module. TheDebuglevel logs why a pod was not evicted and is used for troubleshooting.
For example, to run a redistribution cycle every 5 minutes, set deschedulingInterval to Frequent:
- Web UI
- CLI
- Go to System → System Management → Cluster → Platform → Modules.
- Open the
deschedulermodule and go to the Settings tab. - Set the
deschedulingIntervalparameter toFrequentand save the changes.
Run the following command:
d8 k patch moduleconfig descheduler --type merge -p '{"spec":{"version":2,"settings":{"deschedulingInterval":"Frequent"}}}'
Limiting the pods and nodes to process
The following parameters use Kubernetes label selectors to select eviction candidates and nodes checked as destinations:
spec.podLabelSelector: Selects pods by labels.spec.namespaceLabelSelector: Selects pods by the labels of their namespaces.spec.nodeLabelSelector: Selects the nodes that Descheduler checks as destinations when it verifies whether a pod fits before eviction. A pod on a node outside the selector can still be evicted if it fits on a selected node and passes the other eviction checks.
Each selector supports the matchLabels and matchExpressions fields with the In, NotIn, Exists and DoesNotExist operators.
Pod priority threshold
The spec.priorityClassThreshold parameter limits eviction to the pods whose priority is lower than the threshold.
If the parameter is not set, the threshold is the priority of the system-cluster-critical class.
You can set the threshold in one of two ways:
- By class name:
priorityClassThreshold.nameevicts only the pods with a priority lower than the specified priority class. - By numeric value:
priorityClassThreshold.valueevicts the pods with a priority lower than the specified integer.
The following Descheduler evicts only the pods with a priority lower than the high-priority class:
apiVersion: deckhouse.io/v1alpha2
kind: Descheduler
metadata:
name: custom
spec:
priorityClassThreshold:
name: high-priority
strategies:
removeDuplicates:
enabled: true
Protecting pods by StorageClass
The spec.protectedStorageClasses parameter excludes from eviction the pods with a PersistentVolumeClaim of the listed StorageClasses.
Use it for the pods whose data stays on one node, for example with local volumes.
The following Descheduler balances the CPU load and does not evict the pods with a PersistentVolumeClaim of the local-path StorageClass. Replace local-path with the name of the StorageClass to protect:
apiVersion: deckhouse.io/v1alpha2
kind: Descheduler
metadata:
name: protect-local-storage
spec:
protectedStorageClasses:
- local-path
strategies:
lowNodeUtilization:
enabled: true
thresholds:
cpu: 20
targetThresholds:
cpu: 50
The protection also applies if the PersistentVolumeClaim is not found or its storageClassName is empty.
To turn off the protection, remove protectedStorageClasses: an empty list is not allowed.
Which pods are not evicted
Without the descheduler.alpha.kubernetes.io/evict annotation, the module does not evict a pod in the following cases:
- The pod is in a
d8-*namespace or in thekube-systemnamespace. - The pod has the
system-cluster-criticalorsystem-node-criticalpriority class. - The pod has a priority that is not lower than the priority threshold.
- The pod does not match
spec.podLabelSelector. - The pod uses local storage (an
emptyDirorhostPathvolume) andspec.evictLocalStoragePodsis not set totrue. - The pod uses a PersistentVolumeClaim of a protected StorageClass.
- The pod belongs to a DaemonSet.
- The pod is a static pod, a mirror pod or a terminating pod.
- The pod has no owner and is not in the
Failedphase.
The descheduler.alpha.kubernetes.io/evict annotation lifts these restrictions for a single pod. The following restrictions apply to every pod, including the annotated ones:
- The pod is not selected by
spec.namespaceLabelSelector. - No other suitable node is available for the pod.
- The eviction violates a PodDisruptionBudget: Kubernetes rejects the eviction request.
The full list of restrictions is in the Limitations section of the module documentation.
LowNodeUtilization, HighNodeUtilization, and RemovePodsViolatingInterPodAntiAffinity consider pods in ascending order of priority. For pods with the same priority, the QoS order is BestEffort, Burstable, then Guaranteed.
Descheduling strategies
The spec.strategies section of a Descheduler lists the strategies to enable and configure.
Each strategy has the enabled flag, which is false by default.
Packing pods onto fewer nodes
The HighNodeUtilization strategy concentrates workloads on fewer nodes: it evicts pods from underutilized nodes so that they are placed on the remaining nodes.
Together with cluster autoscaling, this reduces the number of nodes.
To pack evicted pods onto busier nodes, use the high-node-utilization scheduler profile.
Set spec.schedulerName: high-node-utilization in the target workload’s pod template. For a Deployment, set spec.template.spec.schedulerName.
This profile cannot be set as the default one. The strategy does not suit virtual machines: a VirtualMachine has no parameter for the scheduler profile.
A node is underutilized if its resource usage is at or below all the values of thresholds.
The usage is calculated from the sum of pod requests, not from actual consumption.
If a resource is not listed in thresholds, its threshold is 100.
The following Descheduler evicts pods from nodes where CPU and memory requests do not exceed 50% of allocatable resources.
apiVersion: deckhouse.io/v1alpha2
kind: Descheduler
metadata:
name: high-node-utilization
spec:
strategies:
highNodeUtilization:
enabled: true
thresholds:
cpu: 50
memory: 50
In GKE, you cannot configure the default scheduler, but you can use the optimize-utilization strategy or deploy a second custom scheduler.
Redistributing pods from overloaded nodes
The LowNodeUtilization strategy loads the nodes more evenly: it evicts pods from overutilized nodes, assuming that the scheduler places them on underutilized nodes.
- A node is underutilized if its resource usage is at or below all the values of
thresholds. - A node is overutilized if its resource usage exceeds at least one value of
targetThresholds. - Pods on the nodes with the usage between
thresholdsandtargetThresholdsare not evicted.
The thresholds and targetThresholds sections must not be empty and must list the same resources.
The following Descheduler evicts pods from the nodes with a CPU utilization above 50% if there are nodes with a utilization of 20% or lower:
apiVersion: deckhouse.io/v1alpha2
kind: Descheduler
metadata:
name: low-node-utilization
spec:
strategies:
lowNodeUtilization:
enabled: true
thresholds:
cpu: 20
targetThresholds:
cpu: 50
The source of the node resource usage depends on the cluster:
- If the
metrics.k8s.ioAPI group is registered in the cluster, the strategy uses the actual resource consumption from the Metrics API. In Deckhouse Platform, theprometheus-metrics-adaptermodule provides the API group; the module is enabled in theDefaultandManagedbundles. - If the API group is not registered, the usage is calculated from the sum of pod requests, as kube-scheduler does.
In clusters with the control-plane-manager module enabled, the strategy evicts a pod only if kube-scheduler would place it on an underutilized node.
Balancing relative to the average utilization
By default, thresholds and targetThresholds are absolute percentages.
With useDeviationThresholds: true, they are counted from the average utilization of the Ready nodes.
The following Descheduler keeps the nodes within ±5 percentage points of the average CPU utilization.
For example, with an average of 40%, the nodes at or below 35% are underutilized and the nodes above 45% are overutilized.
The evictionLimits.node parameter allows at most two evictions from a node per cycle:
apiVersion: deckhouse.io/v1alpha2
kind: Descheduler
metadata:
name: low-node-utilization-deviation
spec:
strategies:
lowNodeUtilization:
enabled: true
useDeviationThresholds: true
thresholds:
cpu: 5
targetThresholds:
cpu: 5
evictionLimits:
node: 2
Reaching the range is not guaranteed: it depends on the available nodes and the restrictions of the pods.
Balancing by the CPU utilization over 15 minutes
The momentary utilization reacts to short load spikes.
To balance the nodes by their sustained load, set metricsSource: Prometheus: the strategy then uses the node CPU utilization averaged over the last 15 minutes.
The Prometheus source has the following requirements:
- The
prometheusmodule is enabled. If it is disabled, the strategy uses the default source. - Only the
cpukey ofthresholdsandtargetThresholdsis used, and it is required in both sections. - The redistribution interval is
ModerateorRare: the average reflects the evictions with a delay of up to 15 minutes. evictionLimits.nodeis not set: with this source, the strategy evicts one pod from each overutilized node per cycle, and the parameter raises this number.
The following Descheduler selects the nodes by a deviation of 5 percentage points from the average 15-minute CPU utilization:
apiVersion: deckhouse.io/v1alpha2
kind: Descheduler
metadata:
name: low-node-utilization-prometheus
spec:
strategies:
lowNodeUtilization:
enabled: true
metricsSource: Prometheus
useDeviationThresholds: true
thresholds:
cpu: 5
targetThresholds:
cpu: 5
If Prometheus is unavailable or has no data for at least one Ready node, the strategy of this Descheduler skips the cycle.
Removing duplicate pods
The RemoveDuplicates strategy prevents several pods of one controller (ReplicaSet, ReplicationController, StatefulSet) or one Job from running on the same node.
If a node runs two or more such pods, the strategy evicts the excess pods so that they are distributed across the cluster.
This happens, for example, after failed nodes become available again.
To enable the strategy, set strategies.removeDuplicates.enabled:
spec:
strategies:
removeDuplicates:
enabled: true
Evicting pods with too many restarts
The RemovePodsHavingTooManyRestarts strategy evicts a pod when the total number of restarts of its containers reaches the podRestartThreshold threshold.
Restarts of init containers are not counted.
CrashLoopBackOff is one possible symptom. A pod in the Running phase can also be an eviction candidate when its restart count has reached the threshold.
To enable the strategy, set strategies.removePodsHavingTooManyRestarts.enabled:
spec:
strategies:
removePodsHavingTooManyRestarts:
enabled: true
Evicting pods that violate anti-affinity rules
The RemovePodsViolatingInterPodAntiAffinity strategy checks each pod’s own required inter-pod anti-affinity rules.
For example, suppose podB and podC each have a required inter-pod anti-affinity rule that prohibits running on the same node as podA. If all three pods run on the same node, podB and podC are eviction candidates, subject to the other eviction checks.
To enable the strategy, set strategies.removePodsViolatingInterPodAntiAffinity.enabled:
spec:
strategies:
removePodsViolatingInterPodAntiAffinity:
enabled: true
Evicting pods that violate node affinity rules
The RemovePodsViolatingNodeAffinity strategy evicts pods that no longer match their node affinity rules.
The nodeAffinityType parameter sets the rule types to check:
requiredDuringSchedulingIgnoredDuringExecution: If the node stops meeting the rule, for example after a label is removed, and another available node meets it, the strategy evicts the pod.preferredDuringSchedulingIgnoredDuringExecution: If a node that meets the preferred rule appears in the cluster, the strategy evicts the pod from the node it was placed on.
To enable the strategy, set strategies.removePodsViolatingNodeAffinity.enabled:
spec:
strategies:
removePodsViolatingNodeAffinity:
enabled: true
nodeAffinityType:
- requiredDuringSchedulingIgnoredDuringExecution
- preferredDuringSchedulingIgnoredDuringExecution
Evicting pods that violate topology spread constraints
The RemovePodsViolatingTopologySpreadConstraint strategy evicts pods that violate topology spread constraints.
It evicts the minimum number of pods required to balance the topology domains to within the maxSkew of each constraint, for example after a zone recovers from an outage.
To enable the strategy, set strategies.removePodsViolatingTopologySpreadConstraint.enabled:
spec:
strategies:
removePodsViolatingTopologySpreadConstraint:
enabled: true
Evictions in the background
Some pods cannot be evicted at once. For example, a pod of a virtual machine is first moved to another node by live migration, which can take minutes. The module keeps track of such evictions in progress and sends no new request for the pod until the pod leaves the node. The behavior is always on and needs no configuration.
The evictions in progress take places in the evictionLimits.node limit of the LowNodeUtilization strategy. Without the parameter, the module does not limit the number of simultaneous evictions in the background.
An eviction in the background creates no event on the pod and is not shown on the “Descheduler / Workload Happiness” dashboard. The accepted requests are counted by the descheduler_pods_evicted_total metric with the result="background" label.
Rebalancing of virtual machines is described in the VM rebalancing section.
Checking the result and troubleshooting
After you create a Descheduler, check the eviction events and the module log:
d8 k get events -A --field-selector reportingComponent=sigs.k8s.io.descheduler
d8 k logs deployment/descheduler \
-n d8-descheduler \
-c descheduler \
--since=30m
Events are created for all evictions except the background ones. The absence of evictions is not an error by itself: check that suitable nodes are available, the thresholds and the restrictions of the pods. If a utilization data read error occurs, the affected strategy skips the current cycle. The action depends on the log message:
| Message | Cause | Action |
|---|---|---|
unable to find metric entry for |
The Prometheus response has no data for the node | Check that node-exporter metrics are collected for the node and wait for at least two successful scrapes |
unable to find node |
The Metrics API did not return the required node metrics | Check the availability of the registered Metrics API and the node data |
pod does not fit on any other node |
Other nodes do not satisfy the placement conditions of the pod | Check the available resources, selectors, taints and the state of the nodes |
If the cause is not in the log, set logLevel to Debug for the time of troubleshooting: this level logs why a pod was not evicted.
After the cause is resolved, restore the previous level to reduce the log volume.
With the prometheus module enabled, the “Descheduler / Workload Happiness” Grafana dashboard shows the result of redistribution:
the state of workloads (restarts, OOM kills and pods in the Pending, Failed and Unknown phases), the load imbalance between nodes and the evictions by strategy, result, namespace and node.