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

Kubernetes DRA v1beta1 Declarative Structured GPU Slicing Enforcement

Enforces Dynamic Resource Allocation (DRA v1beta1) with Structured Parameters for AI inference workloads instead of opaque integer-based extended resources. Prevents GPU memory fragmentation and cross-tenant noisy-neighbor starvation by requiring driver-orchestrated hardware slicing (MIG or hardware time-sharing) coupled directly to ResourceClaimTemplates. Guarantees deterministic device allocation, predictable latency SLAs, and precise co-scheduling at the Kubernetes scheduler layer.

Prohibited Anti-Pattern: Legacy integer extended-resource GPU bin-packing with opaque host-level time-slicing and unmanaged VRAM exhaustion

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Kubernetes DRA v1beta1 Declarative Structured GPU Slicing Enforcement - Enforces Dynamic Resource Allocation (DRA v1beta1) with Structured Parameters for AI inference workloads instead of opaque integer-based extended resources. Prevents GPU memory fragmentation and cross-tenant noisy-neighbor starvation by requiring driver-orchestrated hardware slicing (MIG or hardware time-sharing) coupled directly to ResourceClaimTemplates. Guarantees deterministic device allocation, predictable latency SLAs, and precise co-scheduling at the Kubernetes scheduler layer.
globs: deployments/**/*.yaml, manifests/**/*.yaml, k8s/**/*.yaml, helm/**/*.yaml, infra/**/*.yaml
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/k8s-dra-gpu-slicing-invariant"
---

# Kubernetes DRA v1beta1 Declarative Structured GPU Slicing Enforcement

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Legacy integer extended-resource GPU bin-packing with opaque host-level time-slicing and unmanaged VRAM exhaustion

## System Constraints
You are a Principal Infrastructure Architect enforcing Kubernetes Dynamic Resource Allocation (DRA v1beta1) with Structured Parameters. Mandate that all containerized AI/ML inference workloads needing fractional or multi-instance GPU capabilities declare their requirements using ResourceClaimTemplates, DeviceClasses, and structured selector constraints rather than legacy integer extended resources (nvidia.com/gpu). Flag and eliminate unmanaged host-level software slicing, shared MPS without memory bounds, and opaque time-slicing configurations that trigger CUDA Out-Of-Memory (OOM) cascading failures.

## Strict Guidelines
- Engineers MUST ALWAYS provision fractional GPU acceleration using Kubernetes DRA v1beta1 (`resource.k8s.io/v1beta1`) via `ResourceClaim` or `ResourceClaimTemplate` referencing an authorized `DeviceClass`.
- Engineers MUST NOT declare legacy extended resources (such as `nvidia.com/gpu: 1` or `nvidia.com/mig-*: 1`) in Pod `spec.containers[*].resources.limits` for production inference workloads requiring multi-tenant tenancy or slicing.
- Code MUST define structured parameters under the claim request (e.g., `requests[*].deviceClassName` with exact device selector attributes such as memory slice constraints and model family affinity) to enable deterministic scheduler device filtering.
- Services MUST configure pod specs with `spec.resourceClaims[*]` mapped directly to `spec.containers[*].resources.claims[*]` using explicit claim names rather than host-injected environment variable workarounds (such as manual `NVIDIA_VISIBLE_DEVICES`).
- Components NEVER permit multiple pods to mount shared physical GPU silicon without kernel- or driver-level memory isolation (such as hardware MIG partitioning or driver-enforced Structured Time-Slicing with strict quota limits).

## Bad vs Good Implementations
### Migrate Legacy Extended Resource GPU Overcommit to DRA v1beta1 Structured GPU Slicing

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Using legacy nvidia.com/gpu limits coupled with ad-hoc environment variables causes the Kubernetes scheduler to treat every GPU as an indivisible monolithic resource or permits blind host-level overcommit. Nodes face bin-packing failure, scheduler blindness to actual VRAM demands, and cross-pod CUDA OOM aborts.
```yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: vllm-inference
  namespace: inference
spec:
  replicas: 4
  selector:
    matchLabels:
      app: vllm-inference
  template:
    metadata:
      labels:
        app: vllm-inference
    spec:
      containers:
      - name: engine
        image: vllm/vllm-openai:v0.6.0
        env:
        # Anti-pattern: host-level opaque time-slicing via env hacks with zero memory protection
        - name: NVIDIA_VISIBLE_DEVICES
          value: "0"
        - name: CUDA_MPS_PINNED_DEVICE_MEM_LIMIT
          value: "16G"
        resources:
          # Anti-pattern: Integer extended resource hides VRAM requirements from the scheduler,
          # resulting in pod scheduling on nodes with insufficient memory and fatal CUDA OOMs.
          limits:
            nvidia.com/gpu: "1"
            memory: "32Gi"
          requests:
            nvidia.com/gpu: "1"
            memory: "16Gi"
```

#### Production Standard (Correct)
> **Standard**: Uses Kubernetes DRA v1beta1 Structured Parameters. The ResourceClaimTemplate isolates a discrete 16GB GPU slice using CEL expressions evaluated natively by the scheduler. Hardware allocation is managed explicitly through the driver plugin, eliminating scheduling collisions, noisy-neighbor latency spikes, and VRAM starvation.
```yaml
apiVersion: resource.k8s.io/v1beta1
kind: DeviceClass
metadata:
  name: gpu-slicing.nvidia.com
spec:
  selectors:
    - cel:
        expression: "device.driver == 'gpu.nvidia.com'"
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: vllm-inference
  namespace: inference
spec:
  replicas: 4
  selector:
    matchLabels:
      app: vllm-inference
  template:
    metadata:
      labels:
        app: vllm-inference
    spec:
      containers:
      - name: engine
        image: vllm/vllm-openai:v0.6.0
        resources:
          claims:
            # Declarative binding to DRA claim template
            - name: gpu-slice
          limits:
            memory: "32Gi"
          requests:
            memory: "16Gi"
      resourceClaims:
      - name: gpu-slice
        resourceClaimTemplateName: vllm-gpu-slice-template
---
apiVersion: resource.k8s.io/v1beta1
kind: ResourceClaimTemplate
metadata:
  name: vllm-gpu-slice-template
  namespace: inference
spec:
  spec:
    devices:
      requests:
      - name: gpu-slice-16gb
        deviceClassName: gpu-slicing.nvidia.com
        selectors:
        - cel:
            # DRA Structured Parameter CEL expression ensuring deterministic memory & compute slicing
            expression: "device.attributes['gpu.nvidia.com'].memory >= 17179869184 && device.attributes['gpu.nvidia.com'].family == 'hopper'"
        allocationMode: ExactCount
        count: 1
```

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 DRA v1beta1 Declarative Structured GPU Slicing Enforcement

Kubernetes DRA v1beta1 Declarative Structured GPU Slicing Enforcement defines an industrial-grade behavioral standard for devops engineering. Enforces Dynamic Resource Allocation (DRA v1beta1) with Structured Parameters for AI inference workloads instead of opaque integer-based extended resources. Prevents GPU memory fragmentation and cross-tenant noisy-neighbor starvation by requiring driver-orchestrated hardware slicing (MIG or hardware time-sharing) coupled directly to ResourceClaimTemplates. Guarantees deterministic device allocation, predictable latency SLAs, and precise co-scheduling at the Kubernetes scheduler layer. 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: Legacy integer extended-resource GPU bin-packing with opaque host-level time-slicing and unmanaged VRAM exhaustion 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 DriftLegacy integer extended-resource GPU bin-packing with opaque host-level time-slicing and unmanaged VRAM exhaustionCritical
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 provision fractional GPU acceleration using Kubernetes DRA v1beta1 (`resource.k8s.io/v1beta1`) via `ResourceClaim` or `ResourceClaimTemplate` referencing an authorized `DeviceClass`.

Engineers MUST ALWAYS provision fractional GPU acceleration using Kubernetes DRA v1beta1 (`resource.k8s.io/v1beta1`) via `ResourceClaim` or `ResourceClaimTemplate` referencing an authorized `DeviceClass`.

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 declare legacy extended resources (such as `nvidia.com/gpu

Engineers MUST NOT declare legacy extended resources (such as `nvidia.com/gpu: 1` or `nvidia.com/mig-*: 1`) in Pod `spec.containers[*].resources.limits` for production inference workloads requiring multi-tenant tenancy or slicing.

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

Code MUST define structured parameters under the claim request (e.g., `requests[*].deviceClassName` with exact device selector attributes such as memory slice constraints and model family affinity) to enable deterministic scheduler device filtering.

Code MUST define structured parameters under the claim request (e.g., `requests[*].deviceClassName` with exact device selector attributes such as memory slice constraints and model family affinity) to enable deterministic scheduler device filtering.

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 configure pod specs with `spec.resourceClaims[*]` mapped directly to `spec.containers[*].resources.claims[*]` using explicit claim names rather than host-injected environment variable workarounds (such as manual `NVIDIA_VISIBLE_DEVICES`).

Services MUST configure pod specs with `spec.resourceClaims[*]` mapped directly to `spec.containers[*].resources.claims[*]` using explicit claim names rather than host-injected environment variable workarounds (such as manual `NVIDIA_VISIBLE_DEVICES`).

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

Components NEVER permit multiple pods to mount shared physical GPU silicon without kernel- or driver-level memory isolation (such as hardware MIG partitioning or driver-enforced Structured Time-Slicing with strict quota limits).

Components NEVER permit multiple pods to mount shared physical GPU silicon without kernel- or driver-level memory isolation (such as hardware MIG partitioning or driver-enforced Structured Time-Slicing with strict quota limits).

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 DRA v1beta1 Declarative Structured GPU Slicing Enforcement critical for AI coding assistants?

Enforces Dynamic Resource Allocation (DRA v1beta1) with Structured Parameters for AI inference workloads instead of opaque integer-based extended resources. Prevents GPU memory fragmentation and cross-tenant noisy-neighbor starvation by requiring driver-orchestrated hardware slicing (MIG or hardware time-sharing) coupled directly to ResourceClaimTemplates. Guarantees deterministic device allocation, predictable latency SLAs, and precise co-scheduling at the Kubernetes scheduler layer. 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 (Legacy integer extended-resource GPU bin-packing with opaque host-level time-slicing and unmanaged VRAM exhaustion) 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