Logo

dev-resources.site

for different kinds of informations.

Pod Topology Spread Constraints

Published at
1/12/2025
Categories
kubernetes
devops
Author
jacktt
Categories
2 categories in total
kubernetes
open
devops
open
Author
6 person written this
jacktt
open
Pod Topology Spread Constraints

Pod Topology Spread Constraints

Pod Topology Spread Constraints - a.k.a topologySpreadConstraints is a field of Pod.spec

It allows you to define how Pods should be spread across different topological domains, such as zones or nodes, to achieve better availability, fault tolerance, and resource utilization.

Main attributes

  • topologyKey: is a string representing a node label key. Kubernetes uses this key to identify and group nodes into topological domains.

    • Common values: kubernetes.io/hostname | topology.kubernetes.io/region
  • maxSkew: Specifies the maximum difference in the number of Pods across topological domains. A lower skew ensures a more even distribution.

  • labelSelector: is used to find matching Pods. Pods that match this label selector are counted to determine the number of Pods in their corresponding topology domain.

  • whenUnsatisfiable: indicates how to deal with a Pod if it doesn't satisfy the spread constraint.

    • DoNotSchedule (default) tells the scheduler not to schedule it.
    • ScheduleAnyway tells the scheduler to still schedule it while prioritizing nodes that minimize the skew.

Benefits of Using TSC

  • Improved Fault Tolerance: By spreading Pods across zones or nodes, the impact of a failure in one domain is minimized.

  • Better Resource Utilization: Ensures even distribution of workloads, preventing overloading specific domains.

  • Customizable Scheduling: Fine-tune how workloads are distributed based on application requirements.

Example

The following spec prefer spreading pods across nodes based on kubernetes.io/hostname.

topologySpreadConstraints:
- maxSkew: 1
  topologyKey: kubernetes.io/hostname
  whenUnsatisfiable: ScheduleAnyway
  labelSelector:
    matchLabels:
      app: hello-world
Enter fullscreen mode Exit fullscreen mode

Reference

https://kubernetes.io/docs/concepts/scheduling-eviction/topology-spread-constraints/

kubernetes Article's
30 articles in total
Favicon
Top Kubernetes CI/CD Tools in 2025
Favicon
Kubernetes Architecture- Worker Node
Favicon
Features of Kubernetes
Favicon
How to develop ecommerce website using WooCommerce plugin?
Favicon
Advanced Load Balancing with Traefik: An Introduction to Progressive Delivery, Mirroring, Sticky Sessions, and Health Checks
Favicon
Can't DNAT After DNAT?
Favicon
AIOps : Investigation par l’IA dans Kubernetes avec HolmesGPT, Ollama et RunPod …
Favicon
How to Solve Common Kubernetes Multi-Cluster Deployment Issues
Favicon
Effortless vCluster Management with Sveltos: An Event-Driven Approach
Favicon
Docker vs kubernetes
Favicon
Kubernetes Security Best Practices
Favicon
Top 7 Kubernetes Certifications in 2025
Favicon
Mastering Kubernetes Storage: A Deep Dive into Persistent Volumes and Claims
Favicon
Kubernetes on Hybrid Cloud: Talos network
Favicon
Automate vCluster Management in EKS with Sveltos and Helm
Favicon
Kubernetes Architecture- Master Node
Favicon
Bulletproof Kubernetes Data Distribution and Big Data Offload Strategy
Favicon
To practice
Favicon
Getting started on MOCO, the MySQL Operator for Kubernetes Part 1
Favicon
Secrets Management 101: A technical approach with AKS, Terraform, and Vault
Favicon
5 errores comunes en Kubernetes y cómo solucionarlos rápidamente
Favicon
Configurando Kind Cluster com Cilium e sem kube-proxy: Um Guia Prático
Favicon
In-Depth Comparative Analysis: Horizontal Pod Autoscaler (HPA) vs. Kubernetes Event-driven Autoscaler (KEDA)
Favicon
Building a Kubernetes operator with Python
Favicon
Powerful Load Balancing Strategies in Kubernetes
Favicon
Kubernetes on Hybrid Cloud: Bare-metal or Hypervisor
Favicon
Pod Topology Spread Constraints
Favicon
Por que e como rodar bancos de dados em diferentes nuvens?
Favicon
Kubernetes on Hybrid Cloud: Persistent storages
Favicon
Setting Up a Multi-Node Kubernetes Cluster with kubeadm

Featured ones: