# Avoiding Kubernetes Pod Topology Spread Constraint Pitfalls

DevFeed: [Avoiding Kubernetes Pod Topology Spread Constraint Pitfalls](<https://devfeed.tech/articles/avoiding-kubernetes-pod-topology-spread-constraint-pitfalls-15450.md>)

Original publisher: [Read original article](<https://medium.com/wise-engineering/avoiding-kubernetes-pod-topology-spread-constraint-pitfalls-d369bb04689e?source=rss----f2565bbe9c46---4>)

Author: Matthew Kennedy

Published: 2023-03-28T09:12:41Z

Content type: tutorial

Language: en

Sources: [Wise Engineering - Medium](<https://devfeed.tech/sources/wise-engineering-medium.md>)

Topics: [Kubernetes](<https://devfeed.tech/topics/kubernetes.md>), [configuration](<https://devfeed.tech/topics/configuration.md>), [Availability](<https://devfeed.tech/topics/availability.md>), [resiliency](<https://devfeed.tech/topics/resiliency.md>), [Amazon Web Services](<https://devfeed.tech/topics/aws.md>), [Cloud](<https://devfeed.tech/topics/cloud.md>)

Tags: [availability](<https://devfeed.tech/tags/availability.md>), [aws](<https://devfeed.tech/tags/aws.md>), [cloud](<https://devfeed.tech/tags/cloud.md>), [configuration](<https://devfeed.tech/tags/configuration.md>), [devops](<https://devfeed.tech/tags/devops.md>), [kubernetes](<https://devfeed.tech/tags/kubernetes.md>), [kubernetes-clusters](<https://devfeed.tech/tags/kubernetes-clusters.md>), [pitfalls](<https://devfeed.tech/tags/pitfalls.md>), [platform-engineering](<https://devfeed.tech/tags/platform-engineering.md>), [resiliency](<https://devfeed.tech/tags/resiliency.md>), [software-engineering](<https://devfeed.tech/tags/software-engineering.md>)

## AI overview

This article explains how Kubernetes Pod Topology Spread Constraints distribute workloads across Availability Zones or nodes. It examines how naive configurations can create unexpected pod skew and potentially cause the loss of two-thirds of pods if one Availability Zone fails.

## Source excerpt

In the Wise Cloud Platform squad we take resiliency, capacity planning and costs seriously. We are always looking for ways to improve how services running on our self-managed Kubernetes clusters in AWS can be made more resistant to system failures without significantly increasing cost. One of the mechanisms we use are Pod Topology Spread Constraints. This is a built-in Kubernetes feature used to distribute workloads across a topology domain, such as Availability Zones or Nodes. In this blog post, we consider Availability Zones to be our topology domain. We discuss how to configure Pod Topology Spread Constraints correctly and how a naive configuration creates unexpected Pod skew. If Pod Topology Spread Constraints are misconfigured and an Availability Zone were to go down, you could lose 2/3rds of your Pods instead of the expected 1/3rd. This will likely negatively impact your customers' ability to use your product. What is wrong with Kubernetes Pod Topology Spread Constraints? Skew is the difference in the number of pods between the most populated and least populated Availability Zone. If we have 3 Availability Zones and 3 Pods, ideally we want a skew of 0, as seen in the diagram below. Diagram showing skew of 0 If we were to add another pod, it could be placed in any of the Availability Zones and our pods would still be distributed as evenly as possible. Our skew would then be 1. If the pods are not evenly distributed, the skew will always be greater than 1. In the case of the diagram below, Availability Zone 1 contains 2 pods and Availability Zone 3 contains zero pods, so the skew is 2. Diagram showing skew of 2 You can configure the Pod Topology Spread Constraints through the topologySpreadConstraints section of a Pods' spec. The Pods to which the configuration is applied is determined through LabelSelectors and what you deem an acceptable distribution is determined by the maxSkew field. Below is an example of a naive topologySpreadConstraints configuration: api