---
name: "kubernetes-topology-spread-constraints"
description: "Distribute pods evenly across availability zones, nodes, and regions to prevent outage blast radius."
metadata:
  author: "Kubernetes"
  version: "1.0.0"
  runtime_compatibility:
    - "codex"
    - "claude-code"
    - "cursor"
    - "windsurf"
triggers:
  - "configure topologyspreadconstraints"
  - "spread pods across availability zones"
  - "set k8s maxskew"
permissions:
  fs_read: true
  fs_write: "workspace"
  shell_exec: false
  net_access: false
---

# Kubernetes Topology Spread Constraints & Affinity

Implements topologySpreadConstraints: configuring topologyKey (topology.kubernetes.io/zone), maxSkew limits, whenUnsatisfiable policies (DoNotSchedule vs ScheduleAnyway), nodeAffinity, and podAntiAffinity.

## When to Invoke
Invoke this skill whenever you need to:
- configure topologyspreadconstraints
- spread pods across availability zones
- set k8s maxskew

## Execution SOP & Rules
1. Add topologySpreadConstraints array inside pod spec: maxSkew: 1, topologyKey: topology.kubernetes.io/zone.
2. Set whenUnsatisfiable: DoNotSchedule for strict multi-AZ guarantees or ScheduleAnyway for soft spreading.
3. Define labelSelector matching the deployment pod template labels.
4. Verify scheduling distribution: kubectl get pods -o wide --show-labels to inspect node and zone assignments.

## Verification Checklist
- Run local linting, syntax validation, and type-checks before reporting completion.
- Ensure all created or modified files adhere to workspace boundaries and avoid uncommitted secrets.
- Verify tests or build commands exit cleanly with return code 0.
