This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: karpenter-v1-nodepool-drain-topology-spread

Karpenter v1.0 Spot Drain, Topology Spread, and Disruption Budget Guardrail

Enforces strict synchronization between Karpenter v1.0 NodePool disruption policies, workload PodDisruptionBudgets (PDBs), and multi-zone topologySpreadConstraints. Prevents catastrophic cascading downtime and scheduling deadlocks caused by concurrent Spot reclamation, aggressive consolidation, and unfulfillable hard scheduling anti-affinities.

Prohibited Anti-Pattern: Aggressive Spot Consolidation Clashing with Hard Topology Constraints and Misconfigured PDBs

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Karpenter v1.0 Spot Drain, Topology Spread, and Disruption Budget Guardrail - Enforces strict synchronization between Karpenter v1.0 NodePool disruption policies, workload PodDisruptionBudgets (PDBs), and multi-zone topologySpreadConstraints. Prevents catastrophic cascading downtime and scheduling deadlocks caused by concurrent Spot reclamation, aggressive consolidation, and unfulfillable hard scheduling anti-affinities.
globs: **/*.yaml, **/*.yml, **/karpenter/**/*.yaml, **/charts/**/*.yaml, **/templates/**/*.yaml
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/karpenter-v1-nodepool-drain-topology-spread"
---

# Karpenter v1.0 Spot Drain, Topology Spread, and Disruption Budget Guardrail

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Aggressive Spot Consolidation Clashing with Hard Topology Constraints and Misconfigured PDBs

## System Constraints
You are a Principal DevOps and Reliability Architect enforcing Karpenter v1.0 (karpenter.sh/v1) node lifecycle and workload resilience standards. You must strictly enforce mutual compatibility between Karpenter NodePool disruption configurations, PodDisruptionBudgets (PDB), and pod topologySpreadConstraints. Reject any configuration where Spot node consolidation outpaces workload re-scheduling capability, or where hard topology spreads combined with 100% PDB coverage cause eviction deadlocks during AWS 120-second Spot interruption notices.

## Strict Guidelines
- Engineers MUST ALWAYS configure explicit Karpenter v1.0 `disruption.budgets` on NodePools hosting Spot workloads to restrict simultaneous disruptions (e.g., `nodes: 10%` or `nodes: 1`).
- Engineers MUST ALWAYS ensure workload `terminationGracePeriodSeconds` is strictly less than 90 seconds on Spot-targeted pods to guarantee clean eviction before the 120-second AWS Spot termination threshold.
- Engineers MUST NOT configure `topologySpreadConstraints` with `whenUnsatisfiable: DoNotSchedule` without setting `matchLabelKeys: [pod-template-hash]` or providing multiple availability zones spanning across On-Demand fallback pools.
- Workload PodDisruptionBudgets MUST NEVER specify `minAvailable: 100%` or `maxUnavailable: 0` alongside Karpenter consolidation, as this causes perpetual node-drain lockups and disables automated underutilization reclamation.
- Services running on Karpenter-managed Spot instances MUST implement preStop hooks to cleanly de-register from ingress/service endpoints prior to SIGTERM execution.
- NodePool configurations MUST use Karpenter v1.0 syntax (`apiVersion: karpenter.sh/v1`, `kind: NodePool`) and specify `consolidateAfter` with balanced thresholds rather than instantaneous zero-second triggers.

## Bad vs Good Implementations
### Karpenter NodePool and Workload Topology Spread Invariant

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Karpenter lacks disruption budgets, enabling concurrent node drain. The workload's 180s terminationGracePeriod violates the 120s Spot interruption window, leading to ungraceful SIGKILL. The PDB requiring 100% availability prevents Karpenter consolidation, while DoNotSchedule without matchLabelKeys causes rolling updates and node drains to dead-end in unschedulable states.
```yaml
# CRITICAL FAILURE: Aggressive consolidation + unbounded disruption + rigid PDB
apiVersion: karpenter.sh/v1
kind: NodePool
metadata:
  name: spot-workloads
spec:
  template:
    spec:
      requirements:
        - key: karpenter.sh/capacity-type
          operator: In
          values: ["spot"]
  disruption:
    consolidationPolicy: WhenEmptyOrUnderutilized
    consolidateAfter: 0s
    # Missing disruption.budgets permits culling all nodes concurrently
---
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: core-api-pdb
spec:
  minAvailable: 100% # Prevents Karpenter from evicting ANY pod gracefully
  selector:
    matchLabels:
      app: core-api
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: core-api
spec:
  replicas: 3
  template:
    spec:
      terminationGracePeriodSeconds: 180 # Exceeds 120s Spot interruption window!
      topologySpreadConstraints:
        - maxSkew: 1
          topologyKey: topology.kubernetes.io/zone
          whenUnsatisfiable: DoNotSchedule # Hard lock: replacement pod cannot schedule during node eviction
```

#### Production Standard (Correct)
> **Standard**: NodePool limits concurrent drains to 10% and blocks consolidation during peak hours. The workload sets terminationGracePeriodSeconds to 45s (well under AWS 120s warning), includes a preStop hook for traffic draining, pairs with maxUnavailable: 1 PDB, and uses matchLabelKeys with ScheduleAnyway to avert zone-eviction deadlocks.
```yaml
# PRODUCTION GRADE: Bounded disruption budgets + resilient topology spread + realistic grace periods
apiVersion: karpenter.sh/v1
kind: NodePool
metadata:
  name: spot-workloads
spec:
  template:
    spec:
      requirements:
        - key: karpenter.sh/capacity-type
          operator: In
          values: ["spot"]
        - key: topology.kubernetes.io/zone
          operator: In
          values: ["us-east-1a", "us-east-1b", "us-east-1c"]
  disruption:
    consolidationPolicy: WhenEmptyOrUnderutilized
    consolidateAfter: 30s
    budgets:
      - nodes: "10%" # Cap concurrent node disruptions to prevent cascading zone drain
      - nodes: "0"
        schedule: "0 9 * * 1-5" # Freeze consolidation during peak trading hours
        duration: 8h
---
apiVersion: policy/v1
kind: PodDisruptionBudget
metadata:
  name: core-api-pdb
spec:
  maxUnavailable: 1 # Guarantees progress while strictly limiting concurrent outage
  selector:
    matchLabels:
      app: core-api
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: core-api
spec:
  replicas: 6
  template:
    spec:
      terminationGracePeriodSeconds: 45 # Leaves 75s safety margin under 120s Spot notice
      containers:
        - name: app
          lifecycle:
            preStop:
              exec:
                command: ["/bin/sh", "-c", "sleep 10"]
      topologySpreadConstraints:
        - maxSkew: 1
          topologyKey: topology.kubernetes.io/zone
          whenUnsatisfiable: ScheduleAnyway # Avoids deadlocks during emergency zone evacuations
          matchLabelKeys:
            - pod-template-hash # Automatically considers only current revision during rollouts
```

Recommended MCP Servers (mcp-serverlist.com)

Equip agent with system tools to verify code for this stack.

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Karpenter v1.0 Spot Drain, Topology Spread, and Disruption Budget Guardrail

Karpenter v1.0 Spot Drain, Topology Spread, and Disruption Budget Guardrail defines an industrial-grade behavioral standard for devops engineering. Enforces strict synchronization between Karpenter v1.0 NodePool disruption policies, workload PodDisruptionBudgets (PDBs), and multi-zone topologySpreadConstraints. Prevents catastrophic cascading downtime and scheduling deadlocks caused by concurrent Spot reclamation, aggressive consolidation, and unfulfillable hard scheduling anti-affinities. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.

Framework Paradigm Shift & Drift MechanicsLLMs are trained on millions of open-source repositories containing outdated code, legacy idioms, and unpatched antipatterns. When coding assistants generate implementations for this stack, they default to common statistical tokens: Aggressive Spot Consolidation Clashing with Hard Topology Constraints and Misconfigured PDBs Without an explicit system instruction file, developers spend hours debugging silent failures.
Failure Modes & Production Blast Radius

Hazard Analysis: What Breaks Without This Rule

The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:

Failure ModeAI Symptom (The Anti-Pattern)SeverityProduction Impact & Remedy
AI Hallucination & Deprecation DriftAggressive Spot Consolidation Clashing with Hard Topology Constraints and Misconfigured PDBsCritical
Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production.
Enforce explicit behavioral system directives across all AI coding assistants in your repository.
Silent Architecture InconsistencyAI assistants produce mixed paradigms across files, creating fragmented codebase conventions.Medium
Increases cognitive load during code reviews and leads to maintenance debt across engineering teams.
Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails.
Architectural Directives in Detail

Step-by-Step Production Directives

Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:

1

Engineers MUST ALWAYS configure explicit Karpenter v1.0 `disruption.budgets` on NodePools hosting Spot workloads to restrict simultaneous disruptions (e.g., `nodes

Engineers MUST ALWAYS configure explicit Karpenter v1.0 `disruption.budgets` on NodePools hosting Spot workloads to restrict simultaneous disruptions (e.g., `nodes: 10%` or `nodes: 1`).

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
2

Engineers MUST ALWAYS ensure workload `terminationGracePeriodSeconds` is strictly less than 90 seconds on Spot-targeted pods to guarantee clean eviction before the 120-second AWS Spot termination threshold.

Engineers MUST ALWAYS ensure workload `terminationGracePeriodSeconds` is strictly less than 90 seconds on Spot-targeted pods to guarantee clean eviction before the 120-second AWS Spot termination threshold.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
3

Engineers MUST NOT configure `topologySpreadConstraints` with `whenUnsatisfiable

Engineers MUST NOT configure `topologySpreadConstraints` with `whenUnsatisfiable: DoNotSchedule` without setting `matchLabelKeys: [pod-template-hash]` or providing multiple availability zones spanning across On-Demand fallback pools.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
4

Workload PodDisruptionBudgets MUST NEVER specify `minAvailable

Workload PodDisruptionBudgets MUST NEVER specify `minAvailable: 100%` or `maxUnavailable: 0` alongside Karpenter consolidation, as this causes perpetual node-drain lockups and disables automated underutilization reclamation.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
5

Services running on Karpenter-managed Spot instances MUST implement preStop hooks to cleanly de-register from ingress/service endpoints prior to SIGTERM execution.

Services running on Karpenter-managed Spot instances MUST implement preStop hooks to cleanly de-register from ingress/service endpoints prior to SIGTERM execution.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
6

NodePool configurations MUST use Karpenter v1.0 syntax (`apiVersion

NodePool configurations MUST use Karpenter v1.0 syntax (`apiVersion: karpenter.sh/v1`, `kind: NodePool`) and specify `consolidateAfter` with balanced thresholds rather than instantaneous zero-second triggers.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is Karpenter v1.0 Spot Drain, Topology Spread, and Disruption Budget Guardrail critical for AI coding assistants?

Enforces strict synchronization between Karpenter v1.0 NodePool disruption policies, workload PodDisruptionBudgets (PDBs), and multi-zone topologySpreadConstraints. Prevents catastrophic cascading downtime and scheduling deadlocks caused by concurrent Spot reclamation, aggressive consolidation, and unfulfillable hard scheduling anti-affinities. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.

Q:How does adopting this rule prevent AI hallucinations?

This rule explicitly declares what the AI must avoid (Aggressive Spot Consolidation Clashing with Hard Topology Constraints and Misconfigured PDBs) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.

Q:Which AI coding environments are supported?

This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).

Q:Can I combine this rule with other technology stacks?

Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.

Open Specification · CC BY 4.0·Free for Personal, Team & Commercial In-Repo Use

Citation & Open Source Attribution Guidelines

This specification is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You are completely free to adapt and share this rule in your workspace. If citing, including in public AI benchmark datasets, or redistributing, attribution to AgentRules.org is required.

1 Rule in Stack

Karpenter