The module lifecycle stage: Generally available version

The module has requirements for installation

The module helps administrators redistribute workloads after the state of the cluster changes. It evicts the pods that match the conditions of the active strategies, after which the cluster scheduler places new pods by the current rules. Pods that cannot be evicted at once, for example, pods of virtual machines, leave the node in the background: a virtual machine is not recreated but moved to another node by live migration.

The work of the module is described with the Descheduler custom resource: each Descheduler object sets the strategies and the pods and nodes they apply to. The module analyzes the cluster state at the interval set in the deschedulingInterval parameter, every 15 minutes by default.

The module is based on the descheduler project.

Main features

The module solves the following tasks:

  • Redistributes pods from overloaded nodes to less loaded ones.
  • Packs pods onto fewer nodes so that the cluster can then be scaled down.
  • Reduces the concentration of identical pods of one controller on one node.
  • Evicts pods that violate node affinity, pod anti-affinity or topology spread constraints.
  • Evicts pods that have reached the set number of container restarts.
  • Limits eviction to the selected pods, namespaces and nodes, to pods with a priority below the set threshold and by the selected StorageClasses.
  • Takes background evictions into account, including live migrations of virtual machines.

How the module works

To redistribute the load, the module uses the rules set in a Descheduler object:

  1. The administrator creates a Descheduler object and configures the required strategies in it.
  2. In each cycle, the module evaluates the state of nodes and pods by the selected data sources.
  3. The module selects candidates according to the configured strategies and checks the eviction conditions.
  4. Kubernetes processes the eviction requests, and the scheduler places new pods.

The redistribution scenarios with step-by-step setup are described in the Pod redistribution section of the Deckhouse Platform documentation.

Strategies

Strategies are enabled and configured in the spec.strategies section of a Descheduler. 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.

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.

A Descheduler processes a virtual machine as its pod. The user labels of a VirtualMachine are copied to this pod, so spec.podLabelSelector selects virtual machines as well.

The spec.priorityClassThreshold parameter limits the processing to the pods whose priority is lower than the threshold.

HighNodeUtilization

The strategy places pods more compactly. It identifies underutilized nodes and evicts pods from them so that the pods are placed on fewer nodes. Together with node autoscaling, this reduces the number of nodes.

An underutilized node is a node whose resource usage is at or below all the threshold values specified in the spec.strategies.highNodeUtilization.thresholds section.

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. The profile cannot be set as the default one. The strategy does not suit virtual machines: a VirtualMachine has no parameter for the scheduler profile.

The strategy is enabled by the spec.strategies.highNodeUtilization.enabled parameter.

Node resource usage takes into account extended resources and is calculated from the sum of pod requests, not from actual consumption. Limits are ignored. This matches kube-scheduler, which uses the same principle when it places pods on nodes.

The strategy always uses pod requests, whether or not the metrics.k8s.io API group is registered in the cluster (the Metrics provider section).

In GKE, you cannot configure the default scheduler, but you can use the optimize-utilization strategy or deploy a second custom scheduler.

LowNodeUtilization

The strategy loads the nodes more evenly. It identifies underutilized nodes and evicts pods from overutilized nodes. The strategy assumes that the evicted pods are recreated on the underutilized nodes, following the normal scheduler behavior.

An underutilized node is a node whose resource usage is at or below all the threshold values specified in the spec.strategies.lowNodeUtilization.thresholds section.

An overutilized node is a node whose resource usage exceeds at least one of the threshold values specified in the spec.strategies.lowNodeUtilization.targetThresholds section.

Nodes with resource usage in the range between thresholds and targetThresholds are considered optimally utilized. Pods on these nodes are not evicted.

The strategy is enabled by the spec.strategies.lowNodeUtilization.enabled parameter.

By default, thresholds and targetThresholds are absolute percentages.

If spec.strategies.lowNodeUtilization.useDeviationThresholds is true, they are counted from the average utilization of all Ready nodes of the cluster: a node is underutilized if its usage is at or below the average minus thresholds, and overutilized if its usage is above the average plus targetThresholds. For example, with an average CPU utilization of 40%, thresholds: {cpu: 5} and targetThresholds: {cpu: 5} make nodes at or below 35% underutilized and nodes above 45% overutilized, so the strategy keeps the nodes within the corridor of ±5% around the average.

The thresholds and targetThresholds sections must not be empty and must list the same resources. Without useDeviationThresholds: true, the thresholds value of each resource must not exceed its targetThresholds value. If the sections violate these requirements, the descheduler stops running the strategies, and the error is visible only in the descheduler log.

To evict pods gradually, set spec.strategies.lowNodeUtilization.evictionLimits.node: the maximum number of pods the strategy evicts from one node in one descheduling cycle. A virtual machine that is still migrating from the node takes a place in the limit in every cycle, so for virtual machines the parameter limits how many of them migrate from one node at the same time. Without the parameter, the module does not limit this number.

The source of the node resource usage depends on whether the metrics.k8s.io API group is registered in the cluster (the Metrics provider section):

  • If the API group is not registered, the usage takes into account extended resources and is calculated from the sum of pod requests, not from actual consumption. Limits are ignored. This matches kube-scheduler, which uses the same principle when it places pods on nodes.
  • If the API group is registered, the strategy uses the actual resource consumption from the Metrics API instead of requests. The values are close to the output of d8 k top, but they no longer match the estimate of kube-scheduler: a node whose requests are exhausted can be considered underutilized, and its pods are not evicted.

CPU utilization averaged over 15 minutes

The momentary values from the Metrics API and pod requests react to short load spikes. To balance nodes by their sustained load, set spec.strategies.lowNodeUtilization.metricsSource to Prometheus. The strategy then uses the node CPU utilization averaged over the last 15 minutes, which the cluster Prometheus calculates from the node-exporter data.

The strategy works in this mode as follows:

  • Only the cpu key of thresholds and targetThresholds is used, as a percentage of the node CPU. The key is required in both sections, other keys are ignored.
  • The prometheus module must be enabled. If it is disabled, the strategy works as with Default, and a warning is written to the Deckhouse Platform log.
  • With useDeviationThresholds: true, the strategy keeps the nodes within a corridor around the 15-minute average CPU utilization of the cluster.
  • The strategy cannot estimate how much one pod adds to the average, so it evicts one pod from each overutilized node in a cycle. With evictionLimits.node set, it evicts up to that number of pods from each overutilized node: in this mode the parameter raises the number of evictions. Do not set evictionLimits.node with this source.
  • The average reflects the evictions with a delay of up to 15 minutes. With the Frequent descheduling interval, a node stays overutilized for several cycles after the evictions and pods are evicted from it again. Use the Moderate or Rare interval with this source.
  • If Prometheus is unavailable or has no data for at least one Ready node, the strategy of this Descheduler skips the cycle. Prometheus has no data for a node if node-exporter does not run on it or fails to be scraped, or if the node has just joined and has not been scraped twice yet. Other Descheduler objects keep working.

An example of a Descheduler for this mode is on the Examples page.

Eviction target check

In clusters with the control-plane-manager module enabled, the strategy requests the expected target node from kube-scheduler before evicting a pod. kube-scheduler runs a trial scheduling cycle for the pod with the source node excluded and returns the nodes with the top score.

The strategy uses the answer as follows:

  • The pod is evicted only if every node with the top score is underutilized in this cycle by the thresholds of the same Descheduler. With useDeviationThresholds: true, this means at or below the average minus thresholds. The check has no thresholds of its own.
  • The pod stays on the node, and the strategy checks the next pod of the same node, if kube-scheduler would place the pod on a node that is not underutilized or finds no node for it.
  • The pod also stays on the node if kube-scheduler does not answer or answers with an error: the strategy does not evict a pod without the check.
  • kube-scheduler pauses the regular scheduling while a check runs, so the number of checks is limited. After 5 checks of the pods of one overutilized node that did not allow an eviction, the node waits for the next cycle. After 100 checks in a cycle, the Descheduler evicts no more pods until the next cycle.
  • If the check finds no suitable node for a pod or one of the top-scoring nodes is not underutilized, the other pods of the same controller on the source node are not checked in this cycle.
  • For a virtual machine, its current pod is checked. The target pod of the live migration is created from the same virtual machine specification, so the result of the check is close to the actual placement but can differ from it.

The check applies to every Descheduler with lowNodeUtilization enabled and cannot be turned off. In managed Kubernetes, where the control-plane-manager module is disabled, the strategy works without the check. The descheduler_simulate_target_check_total metric counts the checks by result.

RemoveDuplicates

The strategy prevents several duplicate pods from running on the same node. Pods are duplicates if they belong to one controller (ReplicaSet, ReplicationController, StatefulSet) or to one Job, are in the same namespace and have the same container images. If a node runs two or more duplicates, the module evicts the excess pods so that they are better distributed across the cluster. Pods of virtual machines are not duplicates: the pod of each virtual machine has its own owner.

The situation can occur if some nodes of the cluster have failed and the pods from them have been moved to other nodes. Once the failed nodes are available again, the strategy evicts the duplicate pods from the other nodes.

The strategy is enabled by the spec.strategies.removeDuplicates.enabled parameter.

RemovePodsHavingTooManyRestarts

The strategy evicts pods with too many restarts. A pod becomes an eviction candidate when the total number of restarts of its containers reaches the spec.strategies.removePodsHavingTooManyRestarts.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.

The strategy is enabled by the spec.strategies.removePodsHavingTooManyRestarts.enabled parameter.

RemovePodsViolatingInterPodAntiAffinity

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.

The strategy is enabled by the spec.strategies.removePodsViolatingInterPodAntiAffinity.enabled parameter.

RemovePodsViolatingNodeAffinity

The strategy evicts pods that violate node affinity rules.

Depending on the spec.strategies.removePodsViolatingNodeAffinity.nodeAffinityType parameter, the strategy treats the requiredDuringSchedulingIgnoredDuringExecution rule of the pod’s node affinity as the requiredDuringSchedulingRequiredDuringExecution rule, and the preferredDuringSchedulingIgnoredDuringExecution rule as the preferredDuringSchedulingPreferredDuringExecution rule.

Example for nodeAffinityType: requiredDuringSchedulingIgnoredDuringExecution. A pod is scheduled to a node that satisfies the requiredDuringSchedulingIgnoredDuringExecution node affinity rule at the time of scheduling. If the node stops satisfying the rule over time and another available node satisfies it, the strategy evicts the pod from the node it was originally scheduled to.

Example for nodeAffinityType: preferredDuringSchedulingIgnoredDuringExecution. A pod is scheduled to a node because no other node satisfied the preferredDuringSchedulingIgnoredDuringExecution node affinity rule at the time of scheduling. If an available node that satisfies the rule appears in the cluster over time, the strategy evicts the pod from the node it was originally scheduled to.

The strategy is enabled by the spec.strategies.removePodsViolatingNodeAffinity.enabled parameter.

RemovePodsViolatingTopologySpreadConstraint

The 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, the strategy rebalances pods across zones after a zone recovers from an outage.

The strategy is enabled by the spec.strategies.removePodsViolatingTopologySpreadConstraint.enabled parameter.

Metrics provider

If the metrics.k8s.io API group is registered in the cluster, the module detects it and switches the LowNodeUtilization strategy to the actual resource consumption from the Metrics API instead of pod requests. In Deckhouse Platform, the prometheus-metrics-adapter module provides the API group. The module is enabled in the Default and Managed bundles, so this mode is usually active. In other clusters, the API group is provided by, for example, metrics-server.

The module switches by the presence of the APIService, not by its availability. The values in thresholds and targetThresholds are then a percentage of the node capacity used according to the actual consumption, not to pod requests. The CPU and memory consumption covers the whole node, including system daemons, and is smoothed by a moving average, so a change shows up in about a minute. For pods, the number of pods is still used. The HighNodeUtilization strategy is not affected: it always uses pod requests.

No user action is required. If the API group is registered after the module has started, the descheduler pod is restarted automatically with the updated settings.

If the metrics.k8s.io API group is not registered in the cluster, resource usage is estimated from pod requests.

Evictions in the background

The module supports evictions in background: the EvictionsInBackground feature of the descheduler project, which is in the alpha stage (KEP-1397). The feature is always on and has no module setting.

Usually every eviction completes at once: the eviction API request either succeeds or is rejected. Some workloads cannot be evicted that way. For example, a pod of a virtual machine has to be live-migrated first, which can take minutes and need retries.

A pod with the descheduler.alpha.kubernetes.io/request-evict-only annotation is evicted in the background as follows:

  1. The module sends an eviction API request for the pod.
  2. The pod is not deleted. The request is accepted for execution, and the answer is the 429 Too Many Requests code with a message that contains Eviction triggered evacuation. Such an answer means that the eviction has started, not that it is rejected. The module treats a 429 answer with another message as a failed eviction.
  3. For the time of the eviction, for example, a live migration, the descheduler.alpha.kubernetes.io/eviction-in-progress annotation is set on the pod.
  4. When the eviction completes, the pod is deleted from the source node.

For virtual machines, the virtualization module sets both annotations, and you do not need to set them manually.

The module keeps track of such pods and sends no new request for them until the pod is gone or the descheduler.alpha.kubernetes.io/eviction-in-progress annotation is removed. The request is sent again in the following cases:

  • The descheduler.alpha.kubernetes.io/eviction-in-progress annotation has not appeared on the pod, and 10–20 minutes have passed since the request.
  • The descheduler pod restarted before the annotation appeared. The pod restarts when the spec of any Descheduler object changes.

The tracked pods take places in the spec.strategies.lowNodeUtilization.evictionLimits.node limit. There is no other limit for background evictions: the other strategies and the LowNodeUtilization strategy without this parameter do not limit the number of simultaneous background evictions.

A background eviction creates no event on the pod and is not counted in the descheduler_pod_evictions_total metric. The accepted requests, including repeated ones, are counted by the descheduler_pods_evicted_total metric with the result="background" label.

Pods without the descheduler.alpha.kubernetes.io/request-evict-only annotation are evicted as usual. In clusters where no controller answers the eviction request as described above, the feature changes nothing.

Limitations

Eviction depends on the protection of pods, the available nodes and the restrictions of the workload. Some of the restrictions can be lifted for a single pod with the descheduler.alpha.kubernetes.io/evict annotation. For a virtual machine, the annotation cannot be set in the VirtualMachine: the virtualization module does not copy annotations with the descheduler.alpha.kubernetes.io/ prefix to the pod of the virtual machine.

Restrictions that the annotation lifts

The restrictions in this table do not apply to a pod with the descheduler.alpha.kubernetes.io/evict annotation. Such a pod is evicted if the restrictions that always apply allow it. Without the annotation, the module does not evict the pods that match at least one of the conditions:

Condition How to change
The pod is in a d8-* namespace or in the kube-system namespace —
The pod has the system-cluster-critical or system-node-critical priority class —
The pod has a priority that is not lower than the spec.priorityClassThreshold value Raise the threshold
The pod does not match the spec.podLabelSelector selector Change the selector
The pod uses local storage: an emptyDir or hostPath volume. Pods of virtual machines match this condition as well Set the spec.evictLocalStoragePods: true parameter
The pod uses a PersistentVolumeClaim of a StorageClass listed in the spec.protectedStorageClasses parameter Remove the StorageClass from the list
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 Failed phase —

Restrictions that always apply

The following restrictions apply to all pods, including the pods with the descheduler.alpha.kubernetes.io/evict annotation:

Condition Behavior
The pod is in a namespace that the spec.namespaceLabelSelector selector does not select The pod is not evicted
No other suitable node is available for the pod The pod is not evicted
The eviction violates a PodDisruptionBudget Kubernetes rejects the eviction request, and the pod stays on the node
The LowNodeUtilization strategy uses the Metrics API, and the metrics cannot be obtained The strategy skips the cycle and does not switch to pod requests
The LowNodeUtilization strategy uses the Prometheus source Only CPU is taken into account. If there is no data for at least one Ready node, the strategy skips the cycle
The RemoveDuplicates strategy has fewer suitable nodes than pods of the controller Several pods of the controller stay on one node

A suitable node is another Ready node that is not cordoned and matches spec.nodeLabelSelector. The pod must fit this node according to nodeSelector, required node affinity, NoSchedule and NoExecute taints, required anti-affinity and resource requests compared with allocatable resources.

The check of a suitable node does not take into account volume topology, host ports, required pod affinity, topology spread constraints and DRA claims. A pod with a local or zonal volume can be evicted although it can return only to the same node or zone.