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

Kubernetes 1.32 In-Place Pod Vertical Resource Scaling Boundary

Governs the dynamic patching of container CPU and memory allocations under Kubernetes 1.32 InPlacePodVerticalScaling. Mandates strict resource resize policies, validation of node allocatable headroom, and sequenced memory step-downs to eliminate pod eviction, container restarts, and kernel out-of-memory (OOM) kills.

Prohibited Anti-Pattern: Patching pod container resources without restartPolicy controls and node capacity pre-checks, triggering node overcommit and silent pod restarts

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Kubernetes 1.32 In-Place Pod Vertical Resource Scaling Boundary - Governs the dynamic patching of container CPU and memory allocations under Kubernetes 1.32 InPlacePodVerticalScaling. Mandates strict resource resize policies, validation of node allocatable headroom, and sequenced memory step-downs to eliminate pod eviction, container restarts, and kernel out-of-memory (OOM) kills.
globs: deployments/**/*.yaml, k8s/**/*.yaml, helm/**/*.yaml, src/controllers/**/*.ts, src/services/k8s/**/*.ts
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/k8s-132-inplace-pod-resource-scaling-boundary"
---

# Kubernetes 1.32 In-Place Pod Vertical Resource Scaling Boundary

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Patching pod container resources without restartPolicy controls and node capacity pre-checks, triggering node overcommit and silent pod restarts

## System Constraints
You are a Principal DevOps and Reliability Engineer enforcing Kubernetes 1.32 In-Place Pod Vertical Resource Scaling boundaries. You mandate strict enforcement of resizePolicy declarations, runtime status verification (allocatedResources vs actual resources), and safe step-down sequences for memory to prevent cgroup OOM kills and accidental pod recycles.

## Strict Guidelines
- Engineers MUST explicitly define 'resizePolicy' for both 'cpu' and 'memory' on every container in Pod templates supporting in-place scaling.
- Engineers MUST set 'restartPolicy: NotRequired' for resources intended to scale dynamically; 'RestartContainer' MUST NOT be used for latency-critical stateful workloads.
- Engineers MUST query and evaluate 'pod.status.resize' and 'pod.status.containerStatuses[].allocatedResources' before dispatching subsequent resource updates.
- Engineers MUST NOT attempt to decrease memory limits below the current working set size ('container_memory_working_set_bytes') reported by cgroups or metrics endpoints.
- Services MUST execute a two-phase commit when decreasing resources: reduce application heap allocation prior to issuing a Kubernetes Pod resize patch.
- Controllers MUST verify node allocatable capacity and existing node reserved resources before issuing scale-up operations to avoid 'Infeasible' resize states.

## Bad vs Good Implementations
### Safe In-Place Vertical Pod Autoscaling Manifest and Patch Controller

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Omits the explicit `resizePolicy` block in pod specifications, causing the kubelet to fall back to default container restart behaviors. Fails to verify whether the pod is currently processing another resize operation (`status.resize`) or check if the target memory limit is lower than the active resident memory, causing instant kernel OOM kills.
```typescript
import * as k8s from '@kubernetes/client-node';

// ANTI-PATTERN: Blindly patching resources without resizePolicy or allocatable inspection
export async function resizePodResources(k8sApi: k8s.CoreV1Api, name: string, namespace: string, newMemory: string, newCpu: string): Promise<void> {
  const patch = {
    spec: {
      containers: [{
        name: 'app',
        resources: {
          limits: { memory: newMemory, cpu: newCpu },
          requests: { memory: newMemory, cpu: newCpu }
        }
      }]
    }
  };
  // Missing resizePolicy results in container restart or node eviction if memory drops below current consumption
  await k8sApi.patchNamespacedPod({
    name,
    namespace,
    body: patch,
  });
}
```

#### Production Standard (Correct)
> **Standard**: Verifies that the target container explicitly declares `restartPolicy: NotRequired` for CPU and memory, validates that a prior resize is not `InProgress`, and guarantees that requested memory scaling remains higher than the active working set size before dispatching the patch.
```typescript
import * as k8s from '@kubernetes/client-node';

interface ResourceSpec {
  cpu: string;
  memory: string;
}

export async function resizePodInPlace(
  k8sApi: k8s.CoreV1Api,
  name: string,
  namespace: string,
  containerName: string,
  newResources: ResourceSpec,
  currentWorkingSetBytes: number
): Promise<void> {
  const pod = await k8sApi.readNamespacedPod({ name, namespace });
  const container = pod.spec?.containers.find(c => c.name === containerName);
  if (!container) throw new Error(`Container ${containerName} not found`);

  // Invariant 1: Ensure container explicitly supports in-place resource scaling
  const policies = container.resizePolicy || [];
  const memPolicy = policies.find(p => p.resourceName === 'memory')?.restartPolicy;
  const cpuPolicy = policies.find(p => p.resourceName === 'cpu')?.restartPolicy;
  if (memPolicy !== 'NotRequired' || cpuPolicy !== 'NotRequired') {
    throw new Error(`Container ${containerName} does not permit in-place scaling without restarts`);
  }

  // Invariant 2: Avoid concurrent resize race condition
  const statusResize = pod.status?.resize;
  if (statusResize === 'InProgress') {
    throw new Error(`Resize operation currently InProgress for pod ${name}`);
  }

  // Invariant 3: Guard against cgroup OOM kill when scaling down memory
  const targetBytes = parseResourceToBytes(newResources.memory);
  if (targetBytes < currentWorkingSetBytes) {
    throw new Error(`Refusing to scale memory to ${targetBytes}B below active working set ${currentWorkingSetBytes}B`);
  }

  const patch = {
    spec: {
      containers: [{
        name: containerName,
        resources: {
          requests: { cpu: newResources.cpu, memory: newResources.memory },
          limits: { cpu: newResources.cpu, memory: newResources.memory }
        }
      }]
    }
  };

  await k8sApi.patchNamespacedPod({
    name,
    namespace,
    body: patch
  });
}

function parseResourceToBytes(mem: string): number {
  const units: Record<string, number> = { Ki: 1024, Mi: 1024 ** 2, Gi: 1024 ** 3 };
  const match = mem.match(/^(\d+)(Ki|Mi|Gi)$/);
  if (!match) return parseInt(mem, 10);
  return parseInt(match[1], 10) * units[match[2]];
}
```

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 Pod Vertical Resource Scaling Boundary

Kubernetes 1.32 In-Place Pod Vertical Resource Scaling Boundary defines an industrial-grade behavioral standard for devops engineering. Governs the dynamic patching of container CPU and memory allocations under Kubernetes 1.32 InPlacePodVerticalScaling. Mandates strict resource resize policies, validation of node allocatable headroom, and sequenced memory step-downs to eliminate pod eviction, container restarts, and kernel out-of-memory (OOM) kills. 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 container resources without restartPolicy controls and node capacity pre-checks, triggering node overcommit and silent pod restarts 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 container resources without restartPolicy controls and node capacity pre-checks, triggering node overcommit and silent pod restartsCritical
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' on every container in Pod templates supporting in-place scaling.

Engineers MUST explicitly define 'resizePolicy' for both 'cpu' and 'memory' on every container in Pod templates supporting in-place scaling.

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 'restartPolicy

Engineers MUST set 'restartPolicy: NotRequired' for resources intended to scale dynamically; 'RestartContainer' MUST NOT be used for latency-critical stateful workloads.

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 query and evaluate 'pod.status.resize' and 'pod.status.containerStatuses[].allocatedResources' before dispatching subsequent resource updates.

Engineers MUST query and evaluate 'pod.status.resize' and 'pod.status.containerStatuses[].allocatedResources' before dispatching subsequent resource updates.

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 NOT attempt to decrease memory limits below the current working set size ('container_memory_working_set_bytes') reported by cgroups or metrics endpoints.

Engineers MUST NOT attempt to decrease memory limits below the current working set size ('container_memory_working_set_bytes') reported by cgroups or metrics endpoints.

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 MUST execute a two-phase commit when decreasing resources

Services MUST execute a two-phase commit when decreasing resources: reduce application heap allocation prior to issuing a Kubernetes Pod resize patch.

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

Controllers MUST verify node allocatable capacity and existing node reserved resources before issuing scale-up operations to avoid 'Infeasible' resize states.

Controllers MUST verify node allocatable capacity and existing node reserved resources before issuing scale-up operations to avoid 'Infeasible' resize states.

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 Pod Vertical Resource Scaling Boundary critical for AI coding assistants?

Governs the dynamic patching of container CPU and memory allocations under Kubernetes 1.32 InPlacePodVerticalScaling. Mandates strict resource resize policies, validation of node allocatable headroom, and sequenced memory step-downs to eliminate pod eviction, container restarts, and kernel out-of-memory (OOM) kills. 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 container resources without restartPolicy controls and node capacity pre-checks, triggering node overcommit and silent pod restarts) 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