DEV Community

Cover image for Pod Topology Spread Constraints
JackTT
JackTT

Posted on

1

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/

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay