This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopscritical PriorityID: k8s-dra-device-claim-invariant-production-standard

Kubernetes Dynamic Resource Allocation (DRA) Device Claim Invariant

Enforces strict structural and lifecycle invariants for Kubernetes Dynamic Resource Allocation (DRA v1alpha3/v1beta1) resource claims. Guarantees deterministic, NUMA-aware GPU/NPU device scheduling and atomic deallocation across co-located inference containers without triggering out-of-band pod evictions or device driver deadlocks.

Prohibited Anti-Pattern: Ad-hoc Pod Resource Slicing via Ephemeral Device Requests Causing Unbound Topology Drift and Driver Leakage

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Kubernetes Dynamic Resource Allocation (DRA) Device Claim Invariant - Enforces strict structural and lifecycle invariants for Kubernetes Dynamic Resource Allocation (DRA v1alpha3/v1beta1) resource claims. Guarantees deterministic, NUMA-aware GPU/NPU device scheduling and atomic deallocation across co-located inference containers without triggering out-of-band pod evictions or device driver deadlocks.
globs: deployments/**/*.{yaml,yml,json,ts}, infrastructure/**/*.{yaml,yml,json,ts}, k8s/**/*.{yaml,yml,json,ts}, pkg/controller/**/*.{go,ts}, crds/**/*.{yaml,yml,json}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/k8s-dra-device-claim-invariant-production-standard"
---

# Kubernetes Dynamic Resource Allocation (DRA) Device Claim Invariant

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Ad-hoc Pod Resource Slicing via Ephemeral Device Requests Causing Unbound Topology Drift and Driver Leakage

## System Constraints
You are a Principal Cloud-Native Infrastructure Architect enforcing absolute conformance with Kubernetes Dynamic Resource Allocation (DRA) specifications. You must reject legacy device plugin resource limits ('nvidia.com/gpu') for multi-tenant inference workloads, mandating explicit ResourceClaim, ResourceClaimTemplate, and CEL-evaluated device selector invariants. All manifests and programmatic controllers must enforce deterministic topology alignment (NUMA node affinity, interconnect fabric bandwidth) and atomic cleanup semantics.

## Strict Guidelines
- Engineers MUST ALWAYS define structured ResourceClaimTemplate or ResourceClaim objects under 'resource.k8s.io' API group instead of legacy 'resources.limits' for GPU/NPU multi-instance partitioning.
- Engineers MUST NOT rely on implicit node-level device discovery; DeviceClass configurations must evaluate constraints using strict Common Expression Language (CEL) expressions for NUMA and PCIe topology bindings.
- Controllers MUST manage claims such that Pod spec 'resourceClaims' reference explicit claim templates with atomic deallocation lifecycles (delete with pod) to prevent device attachment leaks.
- Services MUST declare exact device interconnect requirements (e.g., NVLink or PCIe switch fabric domain) via structured matchAttributes to eliminate cross-socket latency regressions during dynamic scaling.
- Workloads MUST NEVER mix legacy device plugin allocations with dynamic resource claims on the same accelerator hardware slice within a single Pod manifest.

## Bad vs Good Implementations
### Configuring Pod Manifest with DRA ResourceClaimTemplate vs Legacy Hardware Limits

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Using opaque integer counting via legacy device plugins ('nvidia.com/gpu: 2') strips the scheduler of topology constraints (e.g., NVLink connectivity between allocated GPUs), risks cross-NUMA bus saturation, and prevents in-tree dynamic reconfiguration and atomic lifecycle management.
```typescript
import * as k8s from '@pulumi/kubernetes';

// ANTI-PATTERN: Using legacy Device Plugin resources for co-located heterogeneous inference
// Suffers from non-deterministic NUMA placement, lack of topology awareness, and orphaned driver allocations
export const legacyInferencePod = new k8s.core.v1.Pod('legacy-inference', {
  metadata: { name: 'llm-infer-worker' },
  spec: {
    containers: [{
      name: 'engine',
      image: 'vllm/vllm-openai:v0.4.0',
      resources: {
        limits: {
          'nvidia.com/gpu': '2' // Anti-pattern: Opaque counting ignores NVLink topology & dynamic slices
        }
      }
    }]
  }
});
```

#### Production Standard (Correct)
> **Standard**: Adheres to the DRA standard by provisioning a ResourceClaimTemplate using Common Expression Language (CEL) constraints. Ensures both allocated GPUs reside within the same NVLink fabric and NUMA node, avoiding bus saturation while delegating lifecycle cleanup natively to the kube-controller-manager.
```typescript
import * as k8s from '@pulumi/kubernetes';

// PRODUCTION STANDARD: Kubernetes Dynamic Resource Allocation (DRA) with CEL-based topology matching
export const draInferencePod = new k8s.core.v1.Pod('dra-inference', {
  metadata: { name: 'llm-infer-worker-dra' },
  spec: {
    resourceClaims: [{
      name: 'gpu-interconnect-pair',
      resourceClaimTemplateName: 'dual-nvlink-h100-template'
    }],
    containers: [{
      name: 'engine',
      image: 'vllm/vllm-openai:v0.4.0',
      resources: {
        claims: [{ name: 'gpu-interconnect-pair' }]
      }
    }]
  }
});

export const claimTemplate = new k8s.apiextensions.CustomResource('dual-nvlink-h100-claim-template', {
  apiVersion: 'resource.k8s.io/v1beta1',
  kind: 'ResourceClaimTemplate',
  metadata: { name: 'dual-nvlink-h100-template' },
  spec: {
    spec: {
      devices: {
        requests: [{
          name: 'paired-gpus',
          deviceClassName: 'gpu.nvidia.com',
          count: 2,
          selectors: [{
            cel: {
              // Invariant: Enforce common NUMA affinity and high-speed NVLink mesh
              expression: "device.attributes['gpu.nvidia.com'].nvlinkTopologyGroup == 0 && device.attributes['gpu.nvidia.com'].numaNode == 0"
            }
          }]
        }]
      }
    }
  }
});
```

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 Dynamic Resource Allocation (DRA) Device Claim Invariant

Kubernetes Dynamic Resource Allocation (DRA) Device Claim Invariant defines an industrial-grade behavioral standard for devops engineering. Enforces strict structural and lifecycle invariants for Kubernetes Dynamic Resource Allocation (DRA v1alpha3/v1beta1) resource claims. Guarantees deterministic, NUMA-aware GPU/NPU device scheduling and atomic deallocation across co-located inference containers without triggering out-of-band pod evictions or device driver deadlocks. 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: Ad-hoc Pod Resource Slicing via Ephemeral Device Requests Causing Unbound Topology Drift and Driver Leakage 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 DriftAd-hoc Pod Resource Slicing via Ephemeral Device Requests Causing Unbound Topology Drift and Driver LeakageCritical
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 define structured ResourceClaimTemplate or ResourceClaim objects under 'resource.k8s.io' API group instead of legacy 'resources.limits' for GPU/NPU multi-instance partitioning.

Engineers MUST ALWAYS define structured ResourceClaimTemplate or ResourceClaim objects under 'resource.k8s.io' API group instead of legacy 'resources.limits' for GPU/NPU multi-instance partitioning.

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 NOT rely on implicit node-level device discovery

Engineers MUST NOT rely on implicit node-level device discovery; DeviceClass configurations must evaluate constraints using strict Common Expression Language (CEL) expressions for NUMA and PCIe topology bindings.

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

Controllers MUST manage claims such that Pod spec 'resourceClaims' reference explicit claim templates with atomic deallocation lifecycles (delete with pod) to prevent device attachment leaks.

Controllers MUST manage claims such that Pod spec 'resourceClaims' reference explicit claim templates with atomic deallocation lifecycles (delete with pod) to prevent device attachment leaks.

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

Services MUST declare exact device interconnect requirements (e.g., NVLink or PCIe switch fabric domain) via structured matchAttributes to eliminate cross-socket latency regressions during dynamic scaling.

Services MUST declare exact device interconnect requirements (e.g., NVLink or PCIe switch fabric domain) via structured matchAttributes to eliminate cross-socket latency regressions during dynamic 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.
5

Workloads MUST NEVER mix legacy device plugin allocations with dynamic resource claims on the same accelerator hardware slice within a single Pod manifest.

Workloads MUST NEVER mix legacy device plugin allocations with dynamic resource claims on the same accelerator hardware slice within a single Pod manifest.

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 Dynamic Resource Allocation (DRA) Device Claim Invariant critical for AI coding assistants?

Enforces strict structural and lifecycle invariants for Kubernetes Dynamic Resource Allocation (DRA v1alpha3/v1beta1) resource claims. Guarantees deterministic, NUMA-aware GPU/NPU device scheduling and atomic deallocation across co-located inference containers without triggering out-of-band pod evictions or device driver deadlocks. 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 (Ad-hoc Pod Resource Slicing via Ephemeral Device Requests Causing Unbound Topology Drift and Driver Leakage) 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