High availability is an important requirement for applications running in Kubernetes. A Kubernetes cluster can contain multiple worker nodes, but distributing application Pods across those nodes does not automatically protect the application from every infrastructure failure.
Consider an application running five replicas. If all five Pods are scheduled in the same availability zone, a failure in that zone can make the entire application unavailable. The cluster may still have healthy nodes in other zones, but they cannot help if the workload was not distributed across them.
Kubernetes provides scheduling features that help distribute Pods across availability zones, nodes, and other infrastructure boundaries. One of the most useful features is Pod topology spread constraints.
By combining topology spread constraints with Deployments, PodDisruptionBudgets, resource requests, and appropriate autoscaling policies, developers can build applications that remain available during infrastructure failures and maintenance activities.
This article explains how to distribute Kubernetes Pods across availability zones, configure scheduling rules, verify Pod placement, and handle common production challenges.
What Are Availability Zones in Kubernetes?
An availability zone is an isolated infrastructure location within a cloud region. Cloud providers use availability zones to reduce the impact of hardware failures, network problems, power outages, and other infrastructure issues.
For example, a cloud region may contain three availability zones:
Each zone has separate infrastructure, although the exact isolation characteristics depend on the cloud provider.
A Kubernetes cluster can use worker nodes from multiple availability zones. Each node is identified by labels that describe its location.
Kubernetes commonly uses the following standard node labels:
Node label | Purpose | Example |
|---|
topology.kubernetes.io/region
| Identifies the cloud region | us-east-1
|
topology.kubernetes.io/zone
| Identifies the availability zone | us-east-1a
|
kubernetes.io/hostname
| Identifies the node hostname | worker-node-01
|
These labels allow the Kubernetes scheduler to understand where a node is located.
You can inspect node labels using:
kubectl get nodes --show-labels
To display only zone information:
kubectl get nodes \
-L topology.kubernetes.io/region \
-L topology.kubernetes.io/zone
Example output:
NAME STATUS REGION ZONE
worker-01 Ready us-east-1 us-east-1a
worker-02 Ready us-east-1 us-east-1a
worker-03 Ready us-east-1 us-east-1b
worker-04 Ready us-east-1 us-east-1b
worker-05 Ready us-east-1 us-east-1c
worker-06 Ready us-east-1 us-east-1c
This cluster has six worker nodes distributed across three availability zones.
The cloud provider or cluster infrastructure normally supplies these labels. If you manage your own Kubernetes infrastructure, make sure the labels are configured consistently on every applicable node.
Why Distribute Kubernetes Pods Across Availability Zones?
Running multiple replicas is not enough if all replicas depend on the same failure domain.
Suppose an application has six replicas.
Without zone-aware scheduling, Kubernetes may place all six Pods in Zone A because the available nodes in that zone have sufficient resources.
If Zone A becomes unavailable, all six replicas may become unavailable together.
A better distribution would be:
Availability zone | Pods |
|---|
Zone A | 2 |
Zone B | 2 |
Zone C | 2 |
Total | 6 |
If one zone fails, the application can still have four replicas running in the remaining zones.
Distributing Pods across availability zones provides several benefits:
Improved Application Availability
When application replicas are distributed across independent zones, a failure in one zone does not automatically remove every replica.
Traffic can continue reaching healthy Pods in the remaining zones, assuming the networking and application dependencies are also available.
Better Fault Isolation
Applications may experience node failures, network interruptions, or infrastructure maintenance in a particular zone.
Zone-aware placement reduces the possibility that every replica is affected by the same infrastructure event.
Improved Maintenance Flexibility
Cloud infrastructure maintenance and node upgrades can affect individual zones or groups of nodes.
A balanced workload gives the cluster more options when replacing or draining nodes.
Better Scaling Across Infrastructure
When applications scale horizontally, topology-aware scheduling helps distribute new Pods instead of concentrating them in one location.
However, zone distribution does not automatically guarantee equal traffic distribution. Service routing, load balancing, and application capacity must also be considered.
Understand Kubernetes Pod Topology Spread Constraints
Kubernetes provides topologySpreadConstraints to control how Pods are distributed across topology domains.
A topology domain is a group of nodes that share a particular topology label value.
For example, when the topology key is topology.kubernetes.io/zone, all nodes with the same zone value belong to the same domain.
Topology spread constraints allow developers to define how evenly matching Pods should be distributed across those domains.
The main properties are:
Property | Description |
|---|
maxSkew
| Maximum permitted difference in matching Pod counts across eligible domains |
topologyKey
| Node label used to identify the topology domain |
whenUnsatisfiable
| Determines whether an unsatisfied constraint blocks scheduling or influences scheduling preference |
labelSelector
| Identifies the Pods counted for the distribution calculation |
minDomains
| Defines the minimum number of eligible topology domains |
nodeAffinityPolicy
| Controls how node affinity affects eligible-domain calculations |
nodeTaintsPolicy
| Controls how node taints affect eligible-domain calculations |
Two settings are especially important.
maxSkew
The maxSkew property controls how unevenly Pods can be distributed.
For example:
maxSkew: 1
With three eligible zones and six matching Pods, Kubernetes attempts to maintain a distribution such as:
Zone A: 2 Pods
Zone B: 2 Pods
Zone C: 2 Pods
A distribution of three, two, and one Pods has a skew of two between the most populated and least populated domains. It would violate a hard constraint with maxSkew: 1.
whenUnsatisfiable
This property determines what Kubernetes should do when a new Pod cannot satisfy the topology rule.
It supports two important values:
Value | Behavior |
|---|
DoNotSchedule
| The scheduler leaves the Pod pending if scheduling would violate the constraint |
ScheduleAnyway
| The scheduler still schedules the Pod when possible, preferring placements that reduce the imbalance |
Use DoNotSchedule when balanced zone placement is a requirement.
Use ScheduleAnyway when keeping the application schedulable is more important than enforcing an exact distribution.
Neither option guarantees that every zone will always contain a healthy Pod. The cluster must have eligible nodes, sufficient capacity, and appropriate workload configuration.
Configure a Kubernetes Deployment Across Three Availability Zones
Let's create a practical example.
Assume an ASP.NET Core API runs in a Kubernetes cluster with three availability zones. The application needs six replicas, with Pods distributed as evenly as possible.
Create a Deployment manifest named api-deployment.yaml.
apiVersion: apps/v1
kind: Deployment
metadata:
name: orders-api
labels:
app: orders-api
spec:
replicas: 6
selector:
matchLabels:
app: orders-api
strategy:
type: RollingUpdate
rollingUpdate:
maxUnavailable: 1
maxSurge: 1
template:
metadata:
labels:
app: orders-api
spec:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels:
app: orders-api
containers:
- name: orders-api
image: myregistry/orders-api:1.0
ports:
- containerPort: 8080
resources:
requests:
cpu: "250m"
memory: "256Mi"
limits:
cpu: "1000m"
memory: "512Mi"
readinessProbe:
httpGet:
path: /health/ready
port: 8080
initialDelaySeconds: 10
periodSeconds: 10
This configuration defines six replicas and a topology spread constraint based on the availability zone label.
The labelSelector matches Pods with the app: orders-api label. Kubernetes uses these matching Pods when calculating distribution.
The maxSkew: 1 setting limits the imbalance between eligible zones, while DoNotSchedule prevents the scheduler from placing a new Pod if doing so would violate the constraint.
Resource requests are also important. The scheduler uses them when deciding whether a node has enough available capacity for a Pod.
The readiness probe helps ensure that traffic is sent only to Pods that are ready to serve requests.
Apply the configuration:
kubectl apply -f api-deployment.yaml
Check the Deployment:
kubectl get deployments
Check the Pods:
kubectl get pods -l app=orders-api -o wide
The output includes the node on which each Pod is running. You can use this information to inspect the distribution across zones.
Require a Minimum Number of Availability Zones
Sometimes, an application must not run unless a specific number of availability zones are available.
For example, an application designed for three-zone resilience may require all three zones to participate in scheduling.
The minDomains property can help express this requirement.
Update the topology spread constraint:
topologySpreadConstraints:
- maxSkew: 1
minDomains: 3
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels:
app: orders-api
With minDomains: 3, Kubernetes expects at least three eligible topology domains for the constraint.
If fewer than three eligible domains are available, the global minimum used for skew calculation becomes zero. With maxSkew: 1, this can prevent additional matching Pods from being scheduled when an existing domain already contains a matching Pod.
This is useful when an application must avoid silently concentrating replicas in fewer zones.
However, it can also leave Pods pending during a zone outage or when a node pool has been scaled down to zero in one zone.
Use minDomains only when the application and its operational requirements justify this scheduling restriction.
Distribute Pods Across Both Zones and Nodes
Distributing Pods across availability zones protects against zone-level failures.
However, multiple Pods may still run on the same worker node within a zone.
If that node fails, several replicas can become unavailable together.
For stronger placement control, define two topology spread constraints:
For example:
topologySpreadConstraints:
- maxSkew: 1
topologyKey: topology.kubernetes.io/zone
whenUnsatisfiable: DoNotSchedule
labelSelector:
matchLabels:
app: orders-api
- maxSkew: 1
topologyKey: kubernetes.io/hostname
whenUnsatisfiable: ScheduleAnyway
labelSelector:
matchLabels:
app: orders-api
The first constraint controls distribution across zones.
The second encourages distribution across nodes.
Using ScheduleAnyway for the node-level constraint allows the scheduler to prioritize better node distribution without making the workload unnecessarily difficult to schedule.
If both constraints use DoNotSchedule, the scheduler must satisfy both simultaneously. This can leave Pods pending when the cluster does not have a suitable combination of nodes and zones.
Always consider available node capacity before applying strict scheduling rules.
Use Pod Anti-Affinity as an Alternative
Kubernetes also supports Pod anti-affinity.
Pod anti-affinity tells the scheduler to avoid placing a Pod in a topology domain that already contains matching Pods.
For example, the following configuration prefers to place application replicas in different availability zones:
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 100
podAffinityTerm:
labelSelector:
matchLabels:
app: orders-api
topologyKey: topology.kubernetes.io/zone
The preferredDuringSchedulingIgnoredDuringExecution setting makes this a scheduling preference rather than a strict requirement.
You can also use:
requiredDuringSchedulingIgnoredDuringExecution
This creates a hard scheduling requirement. The scheduler will not place a matching Pod in a topology domain that already contains a Pod matching the selector.
For example, hard anti-affinity across zones can restrict the workload to one matching Pod per zone. This may be appropriate for a specific architecture, but it can prevent additional replicas from being scheduled when the replica count exceeds the number of available zones.
Topology spread constraints are generally more flexible when the goal is to distribute several replicas evenly rather than limit the number of replicas in each domain.
Pod anti-affinity also requires consistent node labels and can increase scheduling overhead in large clusters.
Protect Application Availability With PodDisruptionBudgets
Topology spread constraints control where Pods are scheduled. They do not protect an application from every planned maintenance operation.
Kubernetes provides PodDisruptionBudgets (PDBs) to control voluntary disruptions.
For example, when an administrator drains a node for maintenance, Kubernetes uses the Eviction API to check whether removing a Pod would violate its disruption budget.
Create a PDB for the Orders API:
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
name: orders-api-pdb
spec:
minAvailable: 4
selector:
matchLabels:
app: orders-api
With six replicas, this configuration requires at least four matching Pods to remain available during voluntary disruptions.
Apply it:
kubectl apply -f orders-api-pdb.yaml
Check the status:
kubectl get pdb orders-api-pdb
A PDB is useful during node maintenance, cluster upgrades, and other operations that use the Eviction API.
However, a PDB does not prevent involuntary disruptions such as unexpected node failures, zone outages, or application crashes. It also does not control every possible deletion operation.
For example, directly deleting a Deployment or Pod can bypass the normal eviction protection.
Use PDBs as one part of an availability strategy, not as a replacement for replicas and zone-aware scheduling.
Configure Horizontal Pod Autoscaling With Zone Distribution
Applications often need to increase or decrease their replica count according to traffic.
Kubernetes Horizontal Pod Autoscaler (HPA) can adjust the number of replicas based on CPU utilization, memory metrics, or custom metrics.
For example:
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: orders-api-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: orders-api
minReplicas: 3
maxReplicas: 12
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
This configuration keeps at least three replicas and allows scaling up to twelve replicas when CPU utilization increases.
The topology spread constraint remains part of the Deployment's Pod template. When HPA creates additional replicas, the scheduler uses the same constraint to place them across eligible zones.
For example, if the cluster has three eligible zones and twelve replicas, a balanced distribution would be:
Availability zone | Replicas |
|---|
Zone A | 4 |
Zone B | 4 |
Zone C | 4 |
Actual placement depends on node capacity, scheduling requirements, and eligible topology domains.
HPA does not create worker nodes. If the cluster lacks sufficient capacity, new Pods may remain pending.
For cloud environments, configure a compatible node autoscaler or managed node pool so that additional nodes can be provisioned when required.
Also verify that the autoscaler understands the workload's topology requirements. If a node pool in one zone scales down to zero, the scheduler may not consider that zone an eligible domain until a node becomes available there.
Handle Persistent Storage Across Availability Zones
Distributing application Pods across zones becomes more complicated when workloads use persistent storage.
For example, a database Pod may use a PersistentVolume backed by a cloud disk that is attached to a particular availability zone.
If the Pod is scheduled in another zone, the volume may not be attachable there.
This can cause the Pod to remain pending even when suitable compute resources are available.
Kubernetes StorageClasses support topology-aware provisioning through volumeBindingMode.
For example:
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
name: regional-storage
provisioner: kubernetes.io/aws-ebs
volumeBindingMode: WaitForFirstConsumer
The provisioner in this example is illustrative; use the CSI driver and parameters supported by your cloud provider and storage platform.
The WaitForFirstConsumer setting delays volume binding and provisioning until a Pod using the volume is scheduled. This allows storage provisioning to consider the Pod's scheduling requirements and topology.
For stateful applications, also evaluate:
Whether storage is zone-specific or replicated across zones.
Whether the storage provider supports multi-zone attachment.
How data replication works between database replicas.
Whether a replacement Pod can access the required volume.
Backup and recovery requirements.
A topology spread constraint alone cannot make a zone-bound storage volume available in another zone.
Verify Pod Distribution Across Availability Zones
After deploying the application, verify that Kubernetes has distributed the Pods as expected.
Start by listing the nodes and their zones:
kubectl get nodes \
-L topology.kubernetes.io/zone
Next, list the application Pods with their assigned nodes:
kubectl get pods \
-l app=orders-api \
-o wide
To display the zone for every application Pod, use:
kubectl get pods \
-l app=orders-api \
-o custom-columns="POD:.metadata.name,NODE:.spec.nodeName,ZONE:.spec.nodeSelector"
The previous command does not directly resolve the zone from the assigned Node object. A more reliable approach is to inspect the Pods and Nodes together.
You can also use:
kubectl get pods \
-l app=orders-api \
-o wide
Then inspect the corresponding node:
kubectl get node worker-01 \
-o jsonpath='{.metadata.labels.topology\.kubernetes\.io/zone}'
For a quick overview of all nodes and zones:
kubectl get nodes \
-o custom-columns="NODE:.metadata.name,ZONE:.metadata.labels.topology\.kubernetes\.io/zone"
If Pods are not distributed as expected, inspect scheduling events:
kubectl describe pod <pod-name>
Look for messages such as:
FailedScheduling
These events can indicate that topology constraints, node affinity, taints, resource requests, or other scheduling requirements prevent the Pod from being placed.
Common Problems When Distributing Pods Across Zones
Problem | Possible cause | Recommended solution |
|---|
Pods remain Pending | Hard topology constraints cannot be satisfied | Check eligible zones, node capacity, and maxSkew |
All Pods run in one zone | Missing or incorrect topology labels, or no effective spread rule | Inspect node labels and Pod constraints |
Pods cannot move to another zone | Persistent volume is zone-specific | Review CSI driver and storage topology |
New replicas are not distributed | Node pools lack capacity in other zones | Configure node autoscaling across zones |
Pods become unavailable during maintenance | No suitable PDB or insufficient replicas | Configure disruption budgets |
Scheduling becomes slow | Complex or extensive Pod anti-affinity rules | Prefer topology spread constraints where appropriate |
Pods are uneven after scale-down | Scheduling constraints do not automatically rebalance existing Pods | Review scaling behavior and consider the Descheduler |
One zone receives too much traffic | Traffic routing is not aligned with Pod distribution | Review Service and external load-balancer routing |
Best Practices for Production Kubernetes Clusters
Run worker nodes across multiple availability zones when the cloud provider and cluster architecture support it.
Use the standard topology.kubernetes.io/zone label for zone-aware scheduling.
Configure topology spread constraints on Deployments and StatefulSets.
Use maxSkew: 1 when a tightly balanced distribution is required.
Choose between DoNotSchedule and ScheduleAnyway based on availability and scheduling requirements.
Use minDomains only when a minimum number of eligible zones is an explicit requirement.
Combine zone-level spreading with node-level spreading when additional fault isolation is needed.
Configure realistic CPU and memory requests so the scheduler can place Pods correctly.
Use readiness and liveness probes to manage application health.
Configure PodDisruptionBudgets for planned maintenance and voluntary evictions.
Use HPA and node autoscaling together when workloads need to scale across zones.
Review persistent volume topology before distributing stateful workloads.
Monitor Pod placement, scheduling failures, and zone-level capacity.
Test the application by simulating node and zone failures where your environment allows it.
Ensure that databases, network endpoints, and other dependencies also support the required availability architecture.
Advantages and Disadvantages of Zone-Based Pod Distribution
Advantages | Disadvantages |
|---|
Reduces dependence on a single availability zone | Requires a multi-zone cluster |
Improves resilience against zone-level failures | May increase cross-zone network traffic |
Helps distribute application replicas evenly | Strict constraints can leave Pods pending |
Supports safer infrastructure maintenance | Requires sufficient capacity in each zone |
Works with Deployments and StatefulSets | Stateful workloads need topology-aware storage |
Integrates with HPA and node autoscaling | Does not automatically guarantee balanced traffic |
Conclusion
Distributing Kubernetes Pods across availability zones is an important part of building highly available applications. Running multiple replicas provides redundancy, but their placement determines how much protection the application receives from infrastructure failures.
Kubernetes topology spread constraints provide a declarative way to control Pod distribution across zones and nodes. By configuring topologySpreadConstraints, developers can define how evenly matching Pods should be scheduled and decide whether an unsatisfied rule should block scheduling or act as a preference.
For production environments, zone-aware scheduling should be combined with PodDisruptionBudgets, resource requests, readiness probes, horizontal autoscaling, and storage topology planning.
Most importantly, test the application under realistic failure scenarios. A multi-zone Kubernetes cluster improves infrastructure resilience, but application availability also depends on networking, storage, databases, and other services.
A well-designed deployment distributes replicas across failure domains and has enough capacity to continue serving traffic when one of those domains becomes unavailable.
Join the conversation! Your thoughts help the community grow.