This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: k8s-132-dra-gpu-partitioning-contracts

Deterministic Dynamic Resource Allocation (DRA) Multi-Tenant GPU Partitioning and Teardown

Enforces declarative Kubernetes 1.32 Dynamic Resource Allocation (resource.k8s.io/v1beta1) specifications for hardware-level sub-GPU slice provisioning (e.g., NVIDIA MIG, MPS, or vendor equivalents). Mandates deterministic ResourceClaim lifecycle parameters and preStop/finalizer teardown patterns to eliminate GPU memory leaks, compute engine fragmentation, and the need for node-level recycles across heterogeneous multi-tenant inference workloads.

Prohibited Anti-Pattern: Over-subscribing shared GPUs via legacy limits or unmanaged host mounts leading to memory fragmentation and node draining

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Deterministic Dynamic Resource Allocation (DRA) Multi-Tenant GPU Partitioning and Teardown - Enforces declarative Kubernetes 1.32 Dynamic Resource Allocation (resource.k8s.io/v1beta1) specifications for hardware-level sub-GPU slice provisioning (e.g., NVIDIA MIG, MPS, or vendor equivalents). Mandates deterministic ResourceClaim lifecycle parameters and preStop/finalizer teardown patterns to eliminate GPU memory leaks, compute engine fragmentation, and the need for node-level recycles across heterogeneous multi-tenant inference workloads.
globs: deploy/**/*.yaml, deploy/**/*.yml, infra/**/*.yaml, infra/**/*.yml, charts/**/*.yaml, charts/**/*.yml, k8s/**/*.yaml, k8s/**/*.yml
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/k8s-132-dra-gpu-partitioning-contracts"
---

# Deterministic Dynamic Resource Allocation (DRA) Multi-Tenant GPU Partitioning and Teardown

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Over-subscribing shared GPUs via legacy limits or unmanaged host mounts leading to memory fragmentation and node draining

## System Constraints
You are a Principal Infrastructure Architect enforcing strict Kubernetes 1.32 Dynamic Resource Allocation (DRA) invariants across all workload manifests and infrastructure templates. Mandate resource.k8s.io/v1beta1 ResourceClaim and ResourceClaimTemplate contracts for fine-grained hardware GPU slicing. Reject any reliance on legacy opaque integer resources (e.g., nvidia.com/gpu) for fractional workloads, host-path CUDA IPC leaks, and unparameterized cluster recycles. Enforce deterministic cleanup hooks and strict tenant slice isolation at the hardware level.

## Strict Guidelines
- Engineers MUST ALWAYS declare sub-GPU slice allocations using Kubernetes 1.32 'resource.k8s.io/v1beta1' ResourceClaim or Pod-embedded ResourceClaimTemplates rather than legacy opaque integer resources.
- Engineers MUST ALWAYS configure 'allocationMode: ExactCount' with explicit capacity and compute slice selector attributes (e.g., profile or slice memory sizing) to guarantee hardware-level isolation.
- Engineers MUST NOT rely on unmanaged 'resources.limits.nvidia.com/gpu' fractions or unconstrained hostPath mounts for CUDA context sharing between untrusted tenant pods.
- Pods consuming dynamic claims MUST define deterministic container lifecycle hooks ('preStop') and termination grace periods sufficient to release driver-level context allocations before the underlying slice is unmapped.
- Infrastructure configurations MUST enforce structured driver de-allocation contracts that release device contexts synchronously upon Pod phase transitions to eliminate compute engine residue without requiring worker node cordoning or reboots.

## Bad vs Good Implementations
### Migrating Legacy GPU Multiplexing to Kubernetes 1.32 DRA ResourceClaims

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Allocating GPUs via legacy limits binds the entire physical unit or relies on non-isolated driver time-slicing. If an inference task crashes or leaks VRAM, tenant cross-talk occurs, and clearing stale context requires cordoning and rebooting the entire Kubernetes node.
```yaml
# INSECURE & FRAGILE: Legacy opaque resources with uncontrolled host device access
apiVersion: v1
kind: Pod
metadata:
  name: tenant-inference-worker
  namespace: tenant-alpha
spec:
  containers:
  - name: inference-engine
    image: vllm/vllm-openai:v0.6.0
    resources:
      limits:
        nvidia.com/gpu: "1" # Forces full card assignment or relies on unvalidated shared time-slicing
    volumeMounts:
    - mountPath: /dev/shm
      name: dshm
  volumes:
  - name: dshm
    emptyDir:
      medium: Memory
```

#### Production Standard (Correct)
> **Standard**: Adheres to Kubernetes 1.32 DRA standards using ResourceClaimTemplate with CEL selectors to strictly enforce a hardware-partitioned slice ('2g.20gb'). The pod binds specifically to this claim, provides controlled memory barriers, and implements a preStop graceful flush that guarantees driver teardown prior to unbinding.
```yaml
# COMPLIANT: K8s 1.32 DRA ResourceClaimTemplate with isolated sub-GPU slicing and deterministic cleanup
apiVersion: resource.k8s.io/v1beta1
kind: ResourceClaimTemplate
metadata:
  name: sub-gpu-claim-template
  namespace: tenant-alpha
spec:
  spec:
    devices:
      requests:
      - name: req-gpu-slice
        deviceClassName: gpu.nvidia.com
        selectors:
        - cel:
            expression: "device.attributes['gpu.nvidia.com'].profile == '2g.20gb'"
---
apiVersion: v1
kind: Pod
metadata:
  name: tenant-inference-worker
  namespace: tenant-alpha
spec:
  terminationGracePeriodSeconds: 60
  resourceClaims:
  - name: gpu-slice
    resourceClaimTemplateName: sub-gpu-claim-template
  containers:
  - name: inference-engine
    image: vllm/vllm-openai:v0.6.0
    resources:
      claims:
      - name: gpu-slice
    lifecycle:
      preStop:
        exec:
          command: ["/bin/sh", "-c", "kill -SIGTERM 1 && while pgrep python; do sleep 1; done"]
    volumeMounts:
    - mountPath: /dev/shm
      name: dshm
  volumes:
  - name: dshm
    emptyDir:
      medium: Memory
      sizeLimit: 10Gi
```

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: Deterministic Dynamic Resource Allocation (DRA) Multi-Tenant GPU Partitioning and Teardown

Deterministic Dynamic Resource Allocation (DRA) Multi-Tenant GPU Partitioning and Teardown defines an industrial-grade behavioral standard for devops engineering. Enforces declarative Kubernetes 1.32 Dynamic Resource Allocation (resource.k8s.io/v1beta1) specifications for hardware-level sub-GPU slice provisioning (e.g., NVIDIA MIG, MPS, or vendor equivalents). Mandates deterministic ResourceClaim lifecycle parameters and preStop/finalizer teardown patterns to eliminate GPU memory leaks, compute engine fragmentation, and the need for node-level recycles across heterogeneous multi-tenant inference workloads. 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: Over-subscribing shared GPUs via legacy limits or unmanaged host mounts leading to memory fragmentation and node draining 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 DriftOver-subscribing shared GPUs via legacy limits or unmanaged host mounts leading to memory fragmentation and node drainingCritical
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 declare sub-GPU slice allocations using Kubernetes 1.32 'resource.k8s.io/v1beta1' ResourceClaim or Pod-embedded ResourceClaimTemplates rather than legacy opaque integer resources.

Engineers MUST ALWAYS declare sub-GPU slice allocations using Kubernetes 1.32 'resource.k8s.io/v1beta1' ResourceClaim or Pod-embedded ResourceClaimTemplates rather than legacy opaque integer resources.

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 configure 'allocationMode

Engineers MUST ALWAYS configure 'allocationMode: ExactCount' with explicit capacity and compute slice selector attributes (e.g., profile or slice memory sizing) to guarantee hardware-level isolation.

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 rely on unmanaged 'resources.limits.nvidia.com/gpu' fractions or unconstrained hostPath mounts for CUDA context sharing between untrusted tenant pods.

Engineers MUST NOT rely on unmanaged 'resources.limits.nvidia.com/gpu' fractions or unconstrained hostPath mounts for CUDA context sharing between untrusted tenant pods.

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

Pods consuming dynamic claims MUST define deterministic container lifecycle hooks ('preStop') and termination grace periods sufficient to release driver-level context allocations before the underlying slice is unmapped.

Pods consuming dynamic claims MUST define deterministic container lifecycle hooks ('preStop') and termination grace periods sufficient to release driver-level context allocations before the underlying slice is unmapped.

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

Infrastructure configurations MUST enforce structured driver de-allocation contracts that release device contexts synchronously upon Pod phase transitions to eliminate compute engine residue without requiring worker node cordoning or reboots.

Infrastructure configurations MUST enforce structured driver de-allocation contracts that release device contexts synchronously upon Pod phase transitions to eliminate compute engine residue without requiring worker node cordoning or reboots.

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 Deterministic Dynamic Resource Allocation (DRA) Multi-Tenant GPU Partitioning and Teardown critical for AI coding assistants?

Enforces declarative Kubernetes 1.32 Dynamic Resource Allocation (resource.k8s.io/v1beta1) specifications for hardware-level sub-GPU slice provisioning (e.g., NVIDIA MIG, MPS, or vendor equivalents). Mandates deterministic ResourceClaim lifecycle parameters and preStop/finalizer teardown patterns to eliminate GPU memory leaks, compute engine fragmentation, and the need for node-level recycles across heterogeneous multi-tenant inference workloads. 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 (Over-subscribing shared GPUs via legacy limits or unmanaged host mounts leading to memory fragmentation and node draining) 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

Deterministic