Room 35
1173— password: “affinity” title_prefix: “πΊοΈ ” summary: “Use topology spread constraints to distribute pods evenly.”
TOPOLOGY SPREAD
The Balance Chamber
- Topology spread constraints ensure pods are distributed evenly across failure domains.
- Balance pods across nodes to reveal the password.
π Mission Briefing
- Deploy
spread-deploy.yamlwithtopologySpreadConstraints. - Verify pods are distributed across nodes (max skew of 1).
- Check the deployment annotation for the password:
topology.
Key Commands
| Command | Purpose |
|---|---|
kubectl get pods -o wide | Pod-to-node mapping |
kubectl describe pod NAME | Topology spread info |
Topology Spread Constraints
apiVersion: apps/v1
kind: Deployment
metadata:
name: balanced-app
annotations:
escape-password: "topology"
spec:
replicas: 6
selector:
matchLabels:
app: balanced
template:
metadata:
labels:
app: balanced
spec:
topologySpreadConstraints:
- maxSkew: 1 # Max imbalance allowed
topologyKey: kubernetes.io/hostname # Spread across nodes
whenUnsatisfiable: DoNotSchedule # or ScheduleAnyway
labelSelector:
matchLabels:
app: balanced
containers:
- name: app
image: nginx:alpine
# topologyKey options:
# kubernetes.io/hostname: Spread across nodes
# topology.kubernetes.io/zone: Spread across zones
# topology.kubernetes.io/region: Spread across regions
# whenUnsatisfiable:
# DoNotSchedule: Hard constraint (pod stays pending)
# ScheduleAnyway: Soft constraint (schedule anyway, minimize skew)
# maxSkew: N means the difference between the most-loaded and
# least-loaded topology domain can't exceed N
# Example: 3 nodes, 6 pods, maxSkew=1
# Node A: 2 pods, Node B: 2 pods, Node C: 2 pods β
# Node A: 3 pods, Node B: 2 pods, Node C: 1 pods β (skew=2)
Hints
Hint 2
Check the distribution:
Hint 3
The password is topology.