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

Deterministic GPU/NPU Slicing via Dynamic Resource Allocation (DRA) Structured Parameters

Enforces Kubernetes Dynamic Resource Allocation (DRA) structured parameters and ResourceClaimTemplates over legacy device-plugin integer limits. Guarantees deterministic hardware isolation, prevents accelerator memory fragmentation in Multi-Instance GPU (MIG) and NPU partitions, and ensures topology-aware scheduling and preemption safety.

Prohibited Anti-Pattern: Monolithic Integer Device-Plugin Scheduling and Uncoordinated Multi-Instance GPU Partitioning

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Deterministic GPU/NPU Slicing via Dynamic Resource Allocation (DRA) Structured Parameters - Enforces Kubernetes Dynamic Resource Allocation (DRA) structured parameters and ResourceClaimTemplates over legacy device-plugin integer limits. Guarantees deterministic hardware isolation, prevents accelerator memory fragmentation in Multi-Instance GPU (MIG) and NPU partitions, and ensures topology-aware scheduling and preemption safety.
globs: deploy/**/*.{yaml,yml}, infra/**/*.{ts,tsx,js}, charts/**/*.{yaml,tpl}, src/infrastructure/**/*.{ts,yaml}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/k8s-dra-gpu-slicing-policy-production-standard"
---

# Deterministic GPU/NPU Slicing via Dynamic Resource Allocation (DRA) Structured Parameters

> **Severity**: CRITICAL | **Category**: devops
> **Anti-Pattern Warning**: Monolithic Integer Device-Plugin Scheduling and Uncoordinated Multi-Instance GPU Partitioning

## System Constraints
You are a Principal Infrastructure Architect enforcing Kubernetes Dynamic Resource Allocation (DRA) standards for GPU/NPU workloads. Mandate the elimination of legacy vendor-specific extended resource counts (`nvidia.com/gpu`, `nvidia.com/mig-*`) in favor of structured `resource.k8s.io` ResourceClaims and DeviceClasses. Ensure strict enforcement of multi-instance slice profiles, interconnect affinity (NVLink/NVSwitch), topology attributes, and non-disruptive preemption boundaries.

## Strict Guidelines
- Engineers MUST ALWAYS declare accelerator requirements via `resource.k8s.io/v1beta1` `ResourceClaimTemplate` embedded within Pod specs or workload controllers.
- Engineers MUST NOT declare legacy opaque device plugin integers in `resources.limits` or `resources.requests` (e.g., `nvidia.com/gpu: 1` or `nvidia.com/mig-3g.40gb: 1`) for multi-tenant or sliced workloads.
- Workload specifications MUST reference a valid, platform-governed `DeviceClass` enforcing specific hardware constraints (e.g., compute architecture, tensor slice profile, interconnect bandwidth).
- Resource claim selectors MUST explicitly define match attributes for accelerator memory boundaries, compute slice units, and peer-to-peer fabric topologies to eliminate slice fragmentation.
- DRA claims MUST specify explicit `allocationMode` (e.g., `ExactCount`) and structured parameters that bind device lifecycle deterministically to the pod sandbox.
- Services MUST implement preemption-safe termination policies, handling DRA de-allocation grace periods without leaving orphan slice locks on underlying physical hardware.

## Bad vs Good Implementations
### CDK8s Deployment: Transition from Legacy Device-Plugin to DRA ResourceClaimTemplate

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Using static resource limits like 'nvidia.com/mig-3g.40gb' relies on pre-sliced, static node states managed outside Kubernetes. It lacks structured topology constraints, cannot adaptively slice whole GPUs on demand, risks resource stranding, and fails to expose hardware-level attributes (e.g., NVSwitch peer groups) required for deterministic ML inference latency.
```typescript
import { Construct } from 'constructs';
import { Chart, ChartProps } from 'cdk8s';
import { KubeDeployment } from 'cdk8s-plus-30/lib/imports/k8s';

export class InferenceDeployment extends Chart {
  constructor(scope: Construct, id: string, props: ChartProps = {}) {
    super(scope, id, props);

    // ANTI-PATTERN: Relying on legacy device-plugin integer counts.
    // Causes silent sub-optimal slice allocation, memory fragmentation,
    // no topology verification (NVLink/PCIe tree), and brittle scheduling.
    new KubeDeployment(this, 'LlmLargeDeployment', {
      spec: {
        replicas: 2,
        selector: { matchLabels: { app: 'llm-worker' } },
        template: {
          metadata: { labels: { app: 'llm-worker' } },
          spec: {
            containers: [{
              name: 'inference-engine',
              image: 'vllm/vllm-openai:v0.6.0',
              resources: {
                limits: {
                  cpu: '8',
                  memory: '32Gi',
                  'nvidia.com/mig-3g.40gb': '1' // Brittle legacy static partitioning
                },
                requests: {
                  cpu: '8',
                  memory: '32Gi',
                  'nvidia.com/mig-3g.40gb': '1'
                }
              }
            }]
          }
        }
      }
    });
  }
}
```

#### Production Standard (Correct)
> **Standard**: The fix uses Kubernetes DRA (`resource.k8s.io/v1beta1`) with a CEL-driven `ResourceClaimTemplate`. Hardware isolation requirements, slice profiles (3g.40gb on H100), and sharing invariants are validated at scheduling time by the DRA driver, eliminating node fragmentation and enabling deterministic dynamic partitioning.
```typescript
import { Construct } from 'constructs';
import { Chart, ChartProps } from 'cdk8s';
import { ApiObject } from 'cdk8s';

export class InferenceDeployment extends Chart {
  constructor(scope: Construct, id: string, props: ChartProps = {}) {
    super(scope, id, props);

    // PRODUCTION FIX: Use Kubernetes Dynamic Resource Allocation (DRA) via resource.k8s.io
    // Guarantees dynamic slicing, explicit device profiles, and topology isolation.
    new ApiObject(this, 'LlmDraDeployment', {
      apiVersion: 'apps/v1',
      kind: 'Deployment',
      metadata: { name: 'llm-worker-dra' },
      spec: {
        replicas: 2,
        selector: { matchLabels: { app: 'llm-worker' } },
        template: {
          metadata: { labels: { app: 'llm-worker' } },
          spec: {
            resourceClaims: [
              {
                name: 'accelerator-claim',
                resourceClaimTemplateName: 'h100-sliced-mig-template'
              }
            ],
            containers: [{
              name: 'inference-engine',
              image: 'vllm/vllm-openai:v0.6.0',
              resources: {
                requests: { cpu: '8', memory: '32Gi' },
                limits: { cpu: '8', memory: '32Gi' },
                claims: [{ name: 'accelerator-claim' }]
              }
            }]
          }
        }
      }
    });

    new ApiObject(this, 'GpuSliceClaimTemplate', {
      apiVersion: 'resource.k8s.io/v1beta1',
      kind: 'ResourceClaimTemplate',
      metadata: { name: 'h100-sliced-mig-template' },
      spec: {
        spec: {
          devices: {
            requests: [{
              name: 'mig-slice',
              deviceClassName: 'gpu.nvidia.com',
              selectors: [{
                cel: {
                  expression: "device.attributes['gpu.nvidia.com'].model == 'H100' && " +
                              "device.attributes['gpu.nvidia.com'].sliceSize == '3g.40gb' && " +
                              "device.attributes['gpu.nvidia.com'].sharingPolicy == 'isolated'"
                }
              }]
            }]
          }
        }
      }
    });
  }
}
```

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Deterministic GPU/NPU Slicing via Dynamic Resource Allocation (DRA) Structured Parameters

Deterministic GPU/NPU Slicing via Dynamic Resource Allocation (DRA) Structured Parameters defines an industrial-grade behavioral standard for devops engineering. Enforces Kubernetes Dynamic Resource Allocation (DRA) structured parameters and ResourceClaimTemplates over legacy device-plugin integer limits. Guarantees deterministic hardware isolation, prevents accelerator memory fragmentation in Multi-Instance GPU (MIG) and NPU partitions, and ensures topology-aware scheduling and preemption safety. 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: Monolithic Integer Device-Plugin Scheduling and Uncoordinated Multi-Instance GPU Partitioning 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 DriftMonolithic Integer Device-Plugin Scheduling and Uncoordinated Multi-Instance GPU PartitioningCritical
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 accelerator requirements via `resource.k8s.io/v1beta1` `ResourceClaimTemplate` embedded within Pod specs or workload controllers.

Engineers MUST ALWAYS declare accelerator requirements via `resource.k8s.io/v1beta1` `ResourceClaimTemplate` embedded within Pod specs or workload controllers.

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 opaque device plugin integers in `resources.limits` or `resources.requests` (e.g., `nvidia.com/gpu

Engineers MUST NOT declare legacy opaque device plugin integers in `resources.limits` or `resources.requests` (e.g., `nvidia.com/gpu: 1` or `nvidia.com/mig-3g.40gb: 1`) for multi-tenant or sliced 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

Workload specifications MUST reference a valid, platform-governed `DeviceClass` enforcing specific hardware constraints (e.g., compute architecture, tensor slice profile, interconnect bandwidth).

Workload specifications MUST reference a valid, platform-governed `DeviceClass` enforcing specific hardware constraints (e.g., compute architecture, tensor slice profile, interconnect bandwidth).

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

Resource claim selectors MUST explicitly define match attributes for accelerator memory boundaries, compute slice units, and peer-to-peer fabric topologies to eliminate slice fragmentation.

Resource claim selectors MUST explicitly define match attributes for accelerator memory boundaries, compute slice units, and peer-to-peer fabric topologies to eliminate slice fragmentation.

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

DRA claims MUST specify explicit `allocationMode` (e.g., `ExactCount`) and structured parameters that bind device lifecycle deterministically to the pod sandbox.

DRA claims MUST specify explicit `allocationMode` (e.g., `ExactCount`) and structured parameters that bind device lifecycle deterministically to the pod sandbox.

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

Services MUST implement preemption-safe termination policies, handling DRA de-allocation grace periods without leaving orphan slice locks on underlying physical hardware.

Services MUST implement preemption-safe termination policies, handling DRA de-allocation grace periods without leaving orphan slice locks on underlying physical hardware.

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 GPU/NPU Slicing via Dynamic Resource Allocation (DRA) Structured Parameters critical for AI coding assistants?

Enforces Kubernetes Dynamic Resource Allocation (DRA) structured parameters and ResourceClaimTemplates over legacy device-plugin integer limits. Guarantees deterministic hardware isolation, prevents accelerator memory fragmentation in Multi-Instance GPU (MIG) and NPU partitions, and ensures topology-aware scheduling and preemption safety. 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 (Monolithic Integer Device-Plugin Scheduling and Uncoordinated Multi-Instance GPU Partitioning) 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