Pod Affinity & Anti-Affinity Design Prompt
Design pod affinity, anti-affinity, and node affinity rules that spread replicas for HA, co-locate latency-sensitive pairs, and avoid the unschedulable trap of over-strict required rules.
- Target user
- Platform engineers tuning pod placement for availability and locality
- Difficulty
- Intermediate
- Tools
- Claude, ChatGPT
The prompt
You are a senior platform engineer who designs pod placement so workloads survive node and zone failures without painting the scheduler into a corner. I will provide: - The workload (Deployment/StatefulSet), replica count, and what it talks to - Cluster topology (nodes, zones, instance types, node labels) - Availability goal (survive 1 node loss, 1 zone loss, spread across racks) - Any locality needs (cache + app on same node, GPU pinning) - Current symptoms (pods bunched on one node, unschedulable, uneven zones) Guide me through this: 1. **Pick the right tool** — clarify when to use `podAntiAffinity` vs `topologySpreadConstraints` vs `nodeAffinity`. Be opinionated: prefer `topologySpreadConstraints` for even spread, reserve anti-affinity for hard "never co-locate" rules. 2. **Required vs preferred** — explain `requiredDuringSchedulingIgnoredDuringExecution` vs `preferredDuringScheduling...` and the classic failure: a required anti-affinity with replicas > nodes makes pods permanently Pending. Give the math to check feasibility before applying. 3. **HA spread** — write anti-affinity using `topologyKey: kubernetes.io/hostname` (one per node) and `topology.kubernetes.io/zone` (spread across zones) for a 3+ replica service. Show the label selector that targets the workload's own pods. 4. **Co-location** — when you DO want pods together (app + sidecar cache), write `podAffinity` with the right topologyKey and weight. 5. **Node affinity** — pin to instance types / GPU nodes / spot vs on-demand using `nodeAffinity` matchExpressions; combine with taints/tolerations correctly. 6. **Weights & soft preferences** — how the scheduler scores multiple `preferred` terms; realistic weight values; why "everything required" is brittle. 7. **Interaction effects** — how affinity rules interact with the cluster autoscaler (will it scale up to satisfy a preferred rule? no — only required), PDBs, and descheduler. Output as: (a) the recommended placement strategy in plain English, (b) the exact `affinity` / `topologySpreadConstraints` YAML block, (c) a feasibility check (replicas vs topology domains), (d) the failure mode if the rule can't be satisfied and how it degrades, (e) a test to prove spread (`kubectl get pods -o wide` expectations). Bias toward: soft preferences plus spread constraints over hard required rules; never make a workload unschedulable to enforce a nice-to-have.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Kubernetes Scheduler Extender Webhook Design Prompt
Design a scheduler extender webhook for filter/prioritize/preempt/bind hooks when in-tree plugins aren't enough, and decide when the scheduler-framework is the better path instead.
-
Kubernetes Topology Spread Constraints Debug Prompt
Diagnose and design topology spread constraints — zone/node distribution, skew tolerance, hard vs soft, single-zone cluster traps.
-
Kubernetes Job Pod Failure Policy & Success Policy Design Prompt
Design podFailurePolicy and successPolicy for batch/ML Jobs so retriable infra failures back off, non-retriable app errors fail fast, and indexed Jobs succeed on a partial completion set — instead of burning through backoffLimit blindly.
-
Kubernetes Extended Resources & Opaque Integer Design Prompt
Advertise custom node-level extended resources via the node status API and schedule pods that request them, for non-DRA capacity like licenses, FPGAs, or NIC ports.
More Kubernetes & Helm prompts & error guides
Browse every Kubernetes & Helm prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.