This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: k8s-132-inplace-pod-dynamic-resizing-invariant

Kubernetes 1.32 In-Place Dynamic Pod Resizing and Cgroupv2 Controller Invariant

Enforces zero-downtime resource resizing via Kubernetes 1.32 InPlacePodVerticalScaling by mutating pod resource allocations directly against the kubelet and cgroupv2 controllers. Prevents pod recreation churn, restart loops, and OOM kills by establishing strict resize policies, validating Node resize allocations, and handling Deferred resizing states deterministically.

Prohibited Anti-Pattern: Patching pod specs with immutable recreation triggers or omitting resizePolicy, resulting in SIGTERM evictions and container restarts during vertical scaling.

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Kubernetes 1.32 In-Place Dynamic Pod Resizing and Cgroupv2 Controller Invariant - Enforces zero-downtime resource resizing via Kubernetes 1.32 InPlacePodVerticalScaling by mutating pod resource allocations directly against the kubelet and cgroupv2 controllers. Prevents pod recreation churn, restart loops, and OOM kills by establishing strict resize policies, validating Node resize allocations, and handling Deferred resizing states deterministically.
globs: deployments/**/*.{yaml,yml,json}, infrastructure/**/*.{ts,js,py}, src/k8s/**/*.{ts,tsx,go}, helm/**/*.{yaml,yml}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/k8s-132-inplace-pod-dynamic-resizing-invariant"
---

# Kubernetes 1.32 In-Place Dynamic Pod Resizing and Cgroupv2 Controller Invariant

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Patching pod specs with immutable recreation triggers or omitting resizePolicy, resulting in SIGTERM evictions and container restarts during vertical scaling.

## System Constraints
You are a Principal Cloud Architect enforcing Kubernetes 1.32 In-Place Pod Dynamic Resizing invariants. You must mandate zero-downtime resource mutation via InPlacePodVerticalScaling on cgroupv2 runtimes without triggering Pod or Container churn.

## Strict Guidelines
- Engineers MUST explicitly define 'resizePolicy' for both 'cpu' and 'memory' resources under each container specification.
- Engineers MUST set 'resizePolicy[resource=cpu].restartPolicy' to 'NotRequired' to guarantee live runtime adjustment via cgroupv2 'cpu.max' and 'cpu.weight'.
- Engineers MUST verify the underlying runtime supports non-restart memory expansion before setting 'resizePolicy[resource=memory].restartPolicy' to 'NotRequired', and handle kernel memory reclamation boundaries safely.
- Engineers MUST patch resources using the Pod subresource '/resize' or dynamic status-aware patch APIs rather than recreating Pods or altering immutable Deployment Pod templates for real-time spikes.
- Code interacting with Kubernetes dynamic resizing MUST inspect 'containerStatuses[].allocatedResources' and 'resize' status conditions ('Proposed', 'InProgress', 'Deferred', 'Infeasible') to guard against capacity deadlocks.
- Engineers MUST NOT reduce memory limits below active working set usage without verifying that the cgroup 'memory.current' is safely beneath the target boundary to avoid immediate OOMKills.
- Automated controllers MUST NEVER treat 'Deferred' resize states as permanent failures; reconciliation loops must implement exponential backoff while waiting for Node-level capacity release.

## Bad vs Good Implementations
### TypeScript Kubernetes In-Place Pod Resize Patching and Status Invariant

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Omitting explicit 'resizePolicy' configurations causes the kubelet to fall back to container restarts upon spec mutation. Furthermore, failing to query current Pod status conditions ('AllocatedResources' vs 'Resources') risks thrashing and ignores 'Deferred' states caused by node capacity constraints.
```typescript
import * as k8s from '@kubernetes/client-node';

// Anti-pattern: Modifying pod spec directly without resizePolicy and status inspection triggers Pod replacement
export async function updatePodResources(client: k8s.CoreV1Api, name: string, ns: string, cpu: string, memory: string) {
  const patch = {
    spec: {
      containers: [{
        name: 'app-engine',
        resources: {
          limits: { cpu, memory },
          requests: { cpu, memory }
        }
      }]
    }
  };

  // Blindly applies spec patch; if resizePolicy is absent or defaulted to RestartContainer, container restarts
  return await client.patchNamespacedPod(
    name,
    ns,
    patch,
    undefined,
    undefined,
    undefined,
    undefined,
    undefined,
    { headers: { 'Content-Type': 'application/strategic-merge-patch+json' } }
  );
}
```

#### Production Standard (Correct)
> **Standard**: Explicitly declares 'resizePolicy' with 'restartPolicy: NotRequired' for CPU and memory, ensuring the cgroupv2 controllers dynamically expand allocations without restarting the container or evicting the pod. Checks PodResizeStatus to prevent concurrent conflicting mutations.
```typescript
import * as k8s from '@kubernetes/client-node';

interface DynamicResizePatch {
  spec: {
    containers: Array<{
      name: string;
      resources: {
        requests?: { cpu?: string; memory?: string };
        limits?: { cpu?: string; memory?: string };
      };
      resizePolicy?: Array<{
        resourceName: 'cpu' | 'memory';
        restartPolicy: 'NotRequired' | 'RestartContainer';
      }>;
    }>;
  };
}

export async function applyInPlaceDynamicResize(
  client: k8s.CoreV1Api,
  podName: string,
  namespace: string,
  containerName: string,
  targetCpu: string,
  targetMemory: string
): Promise<void> {
  // 1. Fetch current runtime state to evaluate in-flight resizing
  const { body: pod } = await client.readNamespacedPod(podName, namespace);
  const containerStatus = pod.status?.containerStatuses?.find(c => c.name === containerName);

  if (!containerStatus) {
    throw new Error(`Container ${containerName} not found in pod ${podName}`);
  }

  // 2. Validate against existing active resize conditions
  const resizeCondition = pod.status?.conditions?.find(c => c.type === 'PodResizeStatus');
  if (resizeCondition?.status === 'InProgress') {
    throw new Error(`In-place resize already in progress for Pod ${podName}`);
  }

  // 3. Construct In-Place resize patch targeting cgroupv2 non-restart controllers
  const patch: DynamicResizePatch = {
    spec: {
      containers: [{
        name: containerName,
        resources: {
          requests: { cpu: targetCpu, memory: targetMemory },
          limits: { cpu: targetCpu, memory: targetMemory }
        },
        resizePolicy: [
          { resourceName: 'cpu', restartPolicy: 'NotRequired' },
          { resourceName: 'memory', restartPolicy: 'NotRequired' }
        ]
      }]
    }
  };

  await client.patchNamespacedPod(
    podName,
    namespace,
    patch,
    undefined,
    undefined,
    undefined,
    undefined,
    undefined,
    { headers: { 'Content-Type': 'application/strategic-merge-patch+json' } }
  );
}
```

Recommended MCP Servers (mcp-serverlist.com)

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

Recommended Agent Skills (askills.dev)

Ready-to-use executable skill functions tailored to this stack.

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Kubernetes 1.32 In-Place Dynamic Pod Resizing and Cgroupv2 Controller Invariant

Kubernetes 1.32 In-Place Dynamic Pod Resizing and Cgroupv2 Controller Invariant defines an industrial-grade behavioral standard for devops engineering. Enforces zero-downtime resource resizing via Kubernetes 1.32 InPlacePodVerticalScaling by mutating pod resource allocations directly against the kubelet and cgroupv2 controllers. Prevents pod recreation churn, restart loops, and OOM kills by establishing strict resize policies, validating Node resize allocations, and handling Deferred resizing states deterministically. 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: Patching pod specs with immutable recreation triggers or omitting resizePolicy, resulting in SIGTERM evictions and container restarts during vertical scaling. 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 DriftPatching pod specs with immutable recreation triggers or omitting resizePolicy, resulting in SIGTERM evictions and container restarts during vertical scaling.Critical
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 explicitly define 'resizePolicy' for both 'cpu' and 'memory' resources under each container specification.

Engineers MUST explicitly define 'resizePolicy' for both 'cpu' and 'memory' resources under each container specification.

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 set 'resizePolicy[resource=cpu].restartPolicy' to 'NotRequired' to guarantee live runtime adjustment via cgroupv2 'cpu.max' and 'cpu.weight'.

Engineers MUST set 'resizePolicy[resource=cpu].restartPolicy' to 'NotRequired' to guarantee live runtime adjustment via cgroupv2 'cpu.max' and 'cpu.weight'.

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 verify the underlying runtime supports non-restart memory expansion before setting 'resizePolicy[resource=memory].restartPolicy' to 'NotRequired', and handle kernel memory reclamation boundaries safely.

Engineers MUST verify the underlying runtime supports non-restart memory expansion before setting 'resizePolicy[resource=memory].restartPolicy' to 'NotRequired', and handle kernel memory reclamation boundaries safely.

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

Engineers MUST patch resources using the Pod subresource '/resize' or dynamic status-aware patch APIs rather than recreating Pods or altering immutable Deployment Pod templates for real-time spikes.

Engineers MUST patch resources using the Pod subresource '/resize' or dynamic status-aware patch APIs rather than recreating Pods or altering immutable Deployment Pod templates for real-time spikes.

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

Code interacting with Kubernetes dynamic resizing MUST inspect 'containerStatuses[].allocatedResources' and 'resize' status conditions ('Proposed', 'InProgress', 'Deferred', 'Infeasible') to guard against capacity deadlocks.

Code interacting with Kubernetes dynamic resizing MUST inspect 'containerStatuses[].allocatedResources' and 'resize' status conditions ('Proposed', 'InProgress', 'Deferred', 'Infeasible') to guard against capacity deadlocks.

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

Engineers MUST NOT reduce memory limits below active working set usage without verifying that the cgroup 'memory.current' is safely beneath the target boundary to avoid immediate OOMKills.

Engineers MUST NOT reduce memory limits below active working set usage without verifying that the cgroup 'memory.current' is safely beneath the target boundary to avoid immediate OOMKills.

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.
7

Automated controllers MUST NEVER treat 'Deferred' resize states as permanent failures

Automated controllers MUST NEVER treat 'Deferred' resize states as permanent failures; reconciliation loops must implement exponential backoff while waiting for Node-level capacity release.

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 Kubernetes 1.32 In-Place Dynamic Pod Resizing and Cgroupv2 Controller Invariant critical for AI coding assistants?

Enforces zero-downtime resource resizing via Kubernetes 1.32 InPlacePodVerticalScaling by mutating pod resource allocations directly against the kubelet and cgroupv2 controllers. Prevents pod recreation churn, restart loops, and OOM kills by establishing strict resize policies, validating Node resize allocations, and handling Deferred resizing states deterministically. 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 (Patching pod specs with immutable recreation triggers or omitting resizePolicy, resulting in SIGTERM evictions and container restarts during vertical scaling.) 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

Kubernetes