Cloud Computing, DevOps

< 1 min

Topology Aware Scheduling Strategies for Kubernetes

Voiced by Amazon Polly

Introduction

Kubernetes scheduling is more than selecting any available worker for a Pod. In a production cluster, workload placement should account for failure domains such as individual nodes and availability zones. A replicated application can still lose all its replicas if its replicas are concentrated in a single failure domain. Pod Topology Spread Constraints provide a declarative way to specify how matching Pods should be distributed across topology domains. Kubernetes documents this feature specifically for improving high availability and resource utilization.

This article focuses on the advanced operational use of topology spreading, how maxSkew works, how hard and soft constraints differ, how topology spreading relates to PodDisruptionBudgets and anti-affinity, and which mistakes commonly lead to Pending Pods or to misleading availability assumptions.

Pioneers in Cloud Consulting & Migration Services

  • Reduced infrastructural costs
  • Accelerated application deployment
Get Started

Why Replicas Alone Do Not Guarantee High Availability?

Imagine a Deployment with three replicas. If all three Pods are scheduled onto one node, the application has three processes but only one effective node-level failure domain. A node outage can remove all replicas at once. If the cluster spans multiple zones, the same principle applies at the zone level.

Topology-aware placement, therefore, aims to make the replica set resilient to failures that matter to the application. Typical objectives include:

What Pod Topology Spread Constraints Control?

The Pod API exposes spec.topologySpreadConstraints. Each constraint describes how matching Pods should be distributed across topology domains. The kube-scheduler evaluates these constraints when selecting a Node for an unscheduled Pod.

The principal fields are:

Understanding maxSkew Correctly

maxSkew controls how uneven the distribution can become. With whenUnsatisfiable: DoNotSchedule, the scheduler compares the number of matching Pods in a candidate domain with the global minimum across eligible domains. For example, with three eligible zones containing 2, 1, and 1 matching Pods, the global minimum is 1. With maxSkew=1, another Pod cannot be placed into the zone already containing 2 because the resulting skew would be 2.

This does not mean maxSkew=1 forces exactly one Pod into every zone. It expresses the maximum permitted imbalance under the constraint rules. Replica count, eligible domains, selectors, node affinity, taints, and available capacity all affect the final result.

Production Example

A common pattern for a stateless service is to spread replicas at both the zone and node levels. The zone constraint protects against zone concentration, while the hostname constraint reduces concentration on a single worker within a zone. Multiple topology spread constraints are combined using logical AND, so a candidate Node must satisfy all of them.

DoNotSchedule vs ScheduleAnyway

DoNotSchedule is a hard scheduling requirement. If no candidate Node can satisfy the topology constraint, the Pod remains unscheduled. ScheduleAnyway is a soft preference: the scheduler still considers topology balance, but it can place the Pod even when the ideal distribution cannot be achieved.

Hard constraints should be used when violating the topology requirement would materially undermine the application availability objective. Soft constraints are often safer when cluster capacity is variable, and application progress is more important than maintaining a strict balance.

Topology Spread vs Pod Anti-Affinity

Pod anti-affinity denotes a relationship in which a Pod should avoid other Pods that match a selector. Topology spread is more directly focused on balancing matching Pods across topology domains. Kubernetes documentation describes topology spread as providing finer control over distribution than traditional affinity and anti-affinity rules.

Use anti-affinity when the fundamental requirement is to repel Pods from one another. Use topology spread when the requirement is to maintain a controlled distribution across nodes, zones, or another topology domain. Combining hard rules should be done carefully because their intersection can eliminate otherwise valid Nodes.

Topology Spread and PodDisruptionBudgets

Topology spreading and PodDisruptionBudgets solve different availability problems. Topology spreading influences where Pods are placed. A PodDisruptionBudget limits how many selected Pods can be unavailable simultaneously during supported voluntary disruptions, such as eviction through the Eviction API.

A PDB does not protect an application from every type of disruption. Kubernetes explicitly states that directly deleting Pods or controllers can bypass PodDisruptionBudgets. PDBs also do not prevent involuntary failures, such as a node crash. For a resilient workload, topology-aware placement, replication, and disruption controls should therefore be considered separate layers.

Example: Combining Topology Spread with a PDB

For a critical stateless service, a practical design can combine three or more replicas, zone-aware topology spreading, node-level spreading, a PDB, readiness probes, appropriate resource requests, and a controlled rolling-update strategy. Each mechanism protects against a different failure or operational condition.

Common Production Mistakes

Using a labelSelector that does not match the workload Pods. Such Pods may not be counted as the operator expects, resulting in misleading placement behavior.

Assuming topology spread creates missing zones. The scheduler works with topology domains represented by eligible Nodes; a topology constraint does not provision new capacity by itself.

Using DoNotSchedule everywhere without validating capacity. Strict constraints can intentionally leave Pods Pending when the cluster cannot satisfy the placement requirement.

Assuming a PDB protects against direct Pod deletion. Kubernetes documents that some disruption paths bypass PDB protection.

Assuming multiple replicas automatically means multiple failure domains. Replica count and topology distribution are separate concerns.

Ignoring topology labels. Kubernetes recommends well-known topology label keys such as topology.kubernetes.io/zone and topology.kubernetes.io/region rather than relying on ambiguous private keys.

Adding many hard affinity, anti-affinity, taint, toleration, resource, and topology rules without testing their combined scheduling effect.

Troubleshooting a Pending Pod Caused by Placement Rules

When a workload unexpectedly remains Pending, start with the scheduler event output and then validate the placement rules systematically:

Operational Best Practices

Define the actual failure domains first. Then encode those requirements as a scheduling policy. Avoid copying a complex rule set without understanding which failure it is intended to mitigate.

Use consistent labels and selectors across the workload and topology constraints. Test scaling, rolling updates, node drains, node failures, and capacity shortages before treating a placement policy as production-ready.

Keep constraints understandable. A theoretically perfect placement policy that operators cannot troubleshoot during an incident can become an operational liability.

Conclusion

High availability in Kubernetes is not achieved simply by increasing replicas. The replicas must be placed across meaningful failure domains, and the scheduling policy must remain compatible with real cluster capacity and operational procedures. Pod Topology Spread Constraints provide a strong declarative mechanism for achieving this balance.

The most important production principle is to model the failure domains that matter to the application and then choose the least restrictive rule that satisfies the availability objective. When topology spreading is combined with replication, sensible resource requests, PodDisruptionBudgets, readiness, and controlled maintenance, Kubernetes workloads become significantly more resilient without relying on manual Pod placement.

Drop a query if you have any questions regarding Kubernetes, and we will get back to you quickly.

Empowering organizations to become ‘data driven’ enterprises with our Cloud experts.

  • Reduced infrastructure costs
  • Timely data-driven decisions
Get Started

About CloudThat

CloudThat is an award-winning company and the first in India to offer cloud training and consulting services worldwide. As an AWS Premier Tier Services Partner, AWS Advanced Training Partner, Microsoft Solutions Partner, and Google Cloud Platform Partner, CloudThat has empowered over 1.1 million professionals through 1000+ cloud certifications, winning global recognition for its training excellence, including 20 MCT Trainers in Microsoft’s Global Top 100 and an impressive 14 awards in the last 9 years. CloudThat specializes in Cloud Migration, Data Platforms, DevOps, Security, IoT, and advanced technologies like Gen AI & AI/ML. It has delivered over 750 consulting projects for 850+ organizations in 30+ countries as it continues to empower professionals and enterprises to thrive in the digital-first world.

FAQs

1. Does Having Multiple Replicas Automatically Provide High Availability?

ANS: – No. Multiple replicas provide redundancy, but they do not guarantee high availability if they are placed on the same Node or in the same availability zone. Topology-aware scheduling helps distribute replicas across different failure domains.

2. What Does maxSkew Mean?

ANS: – maxSkew defines the maximum allowed difference in the number of matching Pods between topology domains. A lower value enforces stricter distribution, while a higher value allows more imbalance.

3. What Is the Difference Between DoNotSchedule and ScheduleAnyway?

ANS: – DoNotSchedule is a hard requirement and prevents scheduling when the constraint cannot be satisfied. ScheduleAnyway is a preference and allows scheduling even when the ideal distribution cannot be achieved.

WRITTEN BY Pawan Choudhary

Pawan works as a Cloud Engineer at CloudThat Technologies, specializing in scalable AWS solutions. As an AWS Certified Solutions Architect – Associate, he has expertise in cloud architecture, Infrastructure as Code (IaC), automation, and security. Pawan also has experience migrating on-premises applications to the cloud while ensuring compliance with the AWS Well-Architected Framework. Passionate about continuous learning, he enjoys solving complex infrastructure challenges and aligning solutions with business goals.

Share

Comments

    Click to Comment

Get The Most Out Of Us

Our support doesn't end here. We have monthly newsletters, study guides, practice questions, and more to assist you in upgrading your cloud career. Subscribe to get them all!