Skip to main content

kubectl drain Pod Pending: Topology Spread Constraints Fix

1. The Incident — Draining a Node Can Leave a Pod Stuck Pending

Diagram showing a Pod staying stuck in Pending state after a node drain while other workloads recover

On a K3s cluster, it's common to cordon and drain nodes one at a time for maintenance such as OS patching. Pods on the target node usually evict cleanly to other nodes, and most workloads recover within seconds. But a Pod from a specific Deployment can stay stuck in a Pending state and never come back.

In this situation, kubectl get pods may show the PodDisruptionBudget (PDB) is configured correctly and eviction itself is permitted, yet a new Pod still isn't scheduled anywhere. It's tempting to suspect a misconfigured PDB, but a different mechanism is usually responsible. This article explains, based on official documentation, how a Pod can stay stuck even when both Topology Spread Constraints and PodDisruptionBudget are working exactly as designed. Manually untangling this kind of configuration interaction every time is a real burden — it's exactly the kind of thing Kubo's Captain UI, which visualizes cluster state, is meant to take off your plate.

2. Investigation — The PDB Is Fine. The Scheduler Is the Problem

Diagram showing the troubleshooting flow of checking kubectl get pdb and kubectl get events to isolate the cause

The first suspect is usually the PodDisruptionBudget. According to the Kubernetes documentation, the Eviction API evaluates the PDB and returns 429 Too Many Requests when an eviction isn't currently permitted (Kubernetes: API-initiated Eviction). But if kubectl get pdb shows disruptionsAllowed at 1 or more, the eviction itself has gone through fine — the Pod has already been evicted correctly, and a new Pod simply isn't being scheduled.

Checking kubectl get events --sort-by='.lastTimestamp' reveals scheduling-failure events pointing to a topology skew violation. The culprit isn't the PDB — it's the Topology Spread Constraints configured on the same Deployment.

3. The Mechanism — When maxSkew and DoNotSchedule Become a Hard Constraint

Diagram comparing DoNotSchedule and ScheduleAnyway behavior under maxSkew

According to the Kubernetes documentation, when you select whenUnsatisfiable: DoNotSchedule, maxSkew defines "the maximum permitted difference between the number of matching pods in the target topology and the global minimum" (the minimum number of matching pods in an eligible domain, or zero if the number of eligible domains is less than MinDomains). For example, if 3 zones have 2, 2, and 1 matching pods respectively, the global minimum is 1. whenUnsatisfiable has two values:

  • DoNotSchedule (hard constraint): if the condition can't be met, the Pod is not scheduled and stays Pending
  • ScheduleAnyway (soft constraint): the scheduler prefers placements that reduce skew but always schedules the Pod

There's also a field that decides which nodes count toward the domain calculation at all: nodeTaintsPolicy. Setting it to Honor excludes nodes carrying a taint the Pod doesn't tolerate from the calculation; the default, Ignore, keeps such nodes in the calculation (nodeTaintsPolicy went beta in v1.26 and graduated to GA in v1.33).

A typical configuration is topologyKey: kubernetes.io/hostname, maxSkew: 1, whenUnsatisfiable: DoNotSchedule — and unless set explicitly, nodeTaintsPolicy defaults to Ignore. The AWS Prescriptive Guidance also describes DoNotSchedule combined with maxSkew and minDomains as the pattern for building a hard requirement. The question is how that hard requirement can break down during a cordon/drain.

4. The Core Issue — A Cordoned Node Still Counts Under the Default nodeTaintsPolicy

Diagram showing how a cordoned node stays in the domain calculation under nodeTaintsPolicy: Ignore and blocks maxSkew from being satisfied

kubectl cordon adds a node.kubernetes.io/unschedulable:NoSchedule taint to the node (kubectl cordon reference). That behavior is working as designed, but it's easy to miss that because nodeTaintsPolicy defaults to Ignore, the cordoned node is not excluded from the Topology Spread Constraints domain calculation.

Consider a topologyKey: kubernetes.io/hostname, maxSkew: 1, whenUnsatisfiable: DoNotSchedule setup with 3 nodes evenly holding 3 replicas (one per node). Cordoning one node and evicting its Pod drops that node's domain count to 0, but under nodeTaintsPolicy: Ignore the domain still counts toward the calculation. At that point the global minimum becomes 0, so placing the evicted Pod on either of the remaining 2 nodes would raise that domain to 2 — a skew of 2 against the global minimum, which violates maxSkew: 1. And the cordoned node itself is off-limits because of its taint. The evicted Pod has nowhere that satisfies both conditions, and it stays Pending.

The direct fix is to set nodeTaintsPolicy: Honor on the Topology Spread Constraints (GA in v1.33, per the Kubernetes documentation). With Honor, the cordoned node — a node carrying a taint the Pod doesn't tolerate — is excluded from the domain calculation. Only the 2 remaining nodes count, the global minimum becomes 1, and the destination domain reaching 2 is a skew of 1 — which satisfies maxSkew: 1.

yaml
topologySpreadConstraints:
  - topologyKey: kubernetes.io/hostname
    maxSkew: 1
    whenUnsatisfiable: DoNotSchedule
    nodeTaintsPolicy: Honor
    labelSelector:
      matchLabels:
        app: example

You can confirm whether this is actually happening by checking the Events section of kubectl describe pod <pod-name>. If a FailedScheduling warning event shows the scheduler couldn't place the Pod due to the topology constraint, check whether nodeTaintsPolicy on that constraint is still left at the default Ignore.

It's worth noting that the technical knowledge base StackHarbor describes a related but different scenario: a maxSkew: 1 hostname constraint under DoNotSchedule where replica count permanently exceeds node count is "unsatisfiable by construction" and will "stay Pending indefinitely" (StackHarbor: Kubernetes Topology Spread Constraints). That's a structurally different situation — a permanent replica/node mismatch — from the temporary domain-accounting issue a cordon creates, which is the focus of this article.

5. Why PodDisruptionBudget Alone Doesn't Protect You — And Other Pitfalls to Watch

Diagram showing PodDisruptionBudget and Topology Spread Constraints as independent mechanisms protecting different things

What this reveals is that PodDisruptionBudget and Topology Spread Constraints are independent features solving different problems. CAST AI's engineering blog notes that the scheduler doesn't inherently track every zone in a cluster by default, and when a node pool scales to zero in an autoscaling environment, the topology domain itself can disappear, leaving no node that satisfies the constraint (CAST AI: Topology Spread Constraints). A node drain creates the same situation temporarily.

Relaxing to ScheduleAnyway (a soft constraint) isn't a free pass either, because it's only evaluated at scheduling time — if the distribution drifts afterward, already-running Pods are never automatically rebalanced. The official Kubernetes Descheduler project addresses this with its RemovePodsViolatingTopologySpreadConstraint strategy, which evicts only the Pods violating the topology rule after the fact. But that strategy still follows the principle of never evicting a Pod in a way that would violate its PDB, so all three mechanisms need to be combined with a clear understanding of which layer each one protects (kubernetes-sigs/descheduler). Interestingly, the original KEP (Kubernetes Enhancement Proposal) notes that Pod Anti-Affinity's strict "at most one Pod per domain" rule was itself prone to blocking placement during rolling updates — a problem Topology Spread Constraints was designed to solve (KEP-895: Pod Topology Spread). It's an ironic twist that the feature built to avoid Anti-Affinity's problem reproduces a similar one when combined with node draining.

6. Putting This Into Practice for K3s Node Maintenance

Checklist diagram for K3s maintenance covering both Topology Spread Constraints and PodDisruptionBudget

The official K3s documentation recommends manually draining and cordoning a node before an upgrade if your workload is sensitive to brief API server outages, and explicitly requires upgrading server nodes one at a time first, then agent nodes (K3s: Manual Upgrades). That "one at a time" unit of work is exactly what creates the momentary node shortage.

If you're running Longhorn for storage, there's an additional wrinkle. Its documentation recommends setting kubectl drain --timeout high enough (or unlimited) for replica rebuilds to finish, and requires that the number of nodes upgraded concurrently stay lower than each volume's replica count (Longhorn: Node Maintenance).

Four practical mitigations are worth adopting:

  • Set nodeTaintsPolicy: Honor on the affected Topology Spread Constraints so cordoned nodes are excluded from the domain calculation (GA in v1.33)
  • Temporarily relax the affected Deployment's whenUnsatisfiable from DoNotSchedule to ScheduleAnyway right before maintenance, then restore it afterward
  • Revisit maxSkew against the actual ratio of replica count to node count
  • Build a maintenance checklist that accounts for both Topology Spread Constraints and PodDisruptionBudget together

Standardizing procedures like this tends to rely on tribal knowledge. If you need to run maintenance reproducibly on-premises or in air-gapped environments, a fully self-managed K3s platform like Kubo On-Premise is worth considering.

7. Summary

PodDisruptionBudget and Topology Spread Constraints both protect availability, but they protect different things. PDB governs "how many Pods are allowed to go down," while Topology Spread Constraints governs "where a Pod is allowed to land." An operation like cordoning/draining a node, which temporarily changes the cluster's own denominator, shakes both preconditions at once.

The key point is to connect, before suspecting a PDB misconfiguration, the fact that "a cordoned node keeps counting toward the domain calculation under the default nodeTaintsPolicy: Ignore" with how maxSkew is calculated. With that lens, you can get from a scheduling-failure event in kubectl get events to the root cause much faster.

If you'd rather not spend engineering time chasing down configuration interactions like this and standardizing maintenance procedures on a K3s-based production cluster, Kubo's AI-Driven Deployment and Captain UI visualization can help. If you're interested, reach out via our contact form.

Related articles

← Back to all posts