Ecstaticloud
Initializing0%
Ecstaticloud Logo
Back to all insights
Enterprise AI & LLMOpsNovember 16, 2026• 8 min read

Optimizing Distributed LLM Inference on Kubernetes with Dynamic GPU Slicing and Karpenter

Discover how to dramatically cut cloud infrastructure costs by implementing dynamic GPU partitioning and fast auto-scaling for high-throughput LLM serving pipelines on Kubernetes. Learn the exact production architecture Ecstaticloud used to achieve sub-100ms inference latency while reducing GPU idle time by 65%.

Running Large Language Models (LLMs) at enterprise scale often presents a stark operational dilemma: pay exorbitant infrastructure costs for idle GPU capacity, or compromise on user experience with high cold-start latencies.

At Ecstaticloud, our production inferencing pipeline was suffering from classic scaling inefficiencies. We were running dedicated NVIDIA A100 (80GB) and H100 nodes for serving popular open-source LLMs (Llama 3 8B, Mistral 7B) alongside embedding models (bge-large-en-v1.5) and speculative decoding draft models. Our average GPU Compute Utilization hoverered around 22%, yet scaling out took anywhere from 7 to 12 minutes using the standard Kubernetes Cluster Autoscaler due to slow node provisioning and massive container image layers.

To solve this, we re-architected our inferencing infrastructure on AWS EKS by combining Dynamic GPU Slicing (NVIDIA MIG & MPS) with Karpenter's Just-In-Time (JIT) Node Provisioning.

In this article, we'll walk through the architectural design, production configuration manifests, and optimizations that enabled us to achieve sub-100ms p95 inference latency while slashing GPU idle time by 65%.


The Root Problem: Resource Asymmetry in LLM Pipelines

LLM inference pipelines rarely consist of a single monolithic model. A production RAG or Agentic workflow typically looks like this:

[User Request] 
      │
      ▼
┌───────────────────────────────────────────┐
│  1. Guardrails / Safety Model (Small)     │ ──► Needs low VRAM, fast throughput
└───────────────────────────────────────────┘
      │
      ▼
┌───────────────────────────────────────────┐
│  2. Query Vector Embedding Model          │ ──► Compute-bound, minimal VRAM
└───────────────────────────────────────────┘
      │
      ▼
┌───────────────────────────────────────────┐
│  3. Speculative Draft Model (e.g., 1.5B)  │ ──► Moderate VRAM, extreme latency sensitivity
└───────────────────────────────────────────┘
      │
      ▼
┌───────────────────────────────────────────┐
│  4. Primary Generative LLM (e.g., 70B)    │ ──► VRAM-heavy, Tensor-Parallel across GPUs
└───────────────────────────────────────────┘

Allocating an entire 80GB GPU to a 1.5B draft model or an embedding service is financially reckless. Conversely, naive time-slicing (sharing a single GPU across pods via context switching) leads to severe latency spikes due to CUDA context-switching overhead and VRAM thrashing.

The Solution Framework

To achieve optimal efficiency, we divided the solution into two distinct control loops:

  1. Hardware-Level Partitioning (Spatial & Process Isolation): Using Multi-Instance GPU (MIG) for rigid hardware isolation, and Multi-Process Service (MPS) for high-throughput process multiplexing.
  2. Cluster-Level Dynamic Scaling: Using Karpenter to provision hyper-specific, heterogeneous GPU instances in seconds, reacting directly to pending pod requirements without static node-group overhead.

Architectural Overview

                      ┌─────────────────────────────────────────┐
                      │          KEDA / HPA Controller          │
                      └────────────────────┬────────────────────┘
                                           │ Scale Pods
                                           ▼
┌─────────────────────────────────────────────────────────────────────────────────┐
│ Kubernetes Control Plane                                                        │
│                                                                                 │
│   ┌──────────────────────────┐             ┌────────────────────────────────┐   │
│   │ Pending Pod: Embedding   │             │ Pending Pod: Llama-3-8B        │   │
│   │ Requests: mig-1g.10gb    │             │ Requests: nvidia.com/gpu: 1    │   │
│   └────────────┬─────────────┘             └───────────────┬────────────────┘   │
└────────────────┼───────────────────────────────────────────┼────────────────────┘
                 │                                           │
                 └─────────────────────┬─────────────────────┘
                                       │ Watches Unschedulable Pods
                                       ▼
┌─────────────────────────────────────────────────────────────────────────────────┐
│ Karpenter Controller                                                            │
│ Evaluates constraints -> Selects optimal EC2 Instance (g5.2xlarge / p4d.24xlarge)│
└──────────────────────────────────────┬──────────────────────────────────────────┘
                                       │ Provisions JIT Node
                                       ▼
┌─────────────────────────────────────────────────────────────────────────────────┐
│ Provisioned GPU Node                                                            │
│ ┌─────────────────────────────────────────────────────────────────────────────┐ │
│ │ NVIDIA GPU Operator + Dynamic Config Manager                                │ │
│ │ ┌─────────────────────────────────────────────────────────────────────────┐ │ │
│ │ │ Physical GPU (e.g., NVIDIA A100-80GB)                                  │ │ │
│ │ │ ┌───────────────────────────┬───────────────────────────┬─────────────┐ │ │ │
│ │ │ │ Slice 1: MIG 3g.40gb      │ Slice 2: MIG 2g.20gb      │ Slice 3...  │ │ │ │
│ │ │ │ (vLLM Llama-3-8B FP16)    │ (MPS Shared: Embeddings)  │             │ │ │ │
│ │ │ └───────────────────────────┴───────────────────────────┴─────────────┘ │ │ │
│ └─┴─────────────────────────────────────────────────────────────────────────┴─┴ │
└─────────────────────────────────────────────────────────────────────────────────┘

Phase 1: Precision GPU Slicing Strategy

Depending on your model weights and traffic profiles, dynamic partitioning must be configured at the driver and operator level.

Hardware Isolation: NVIDIA MIG vs. CUDA MPS

  • NVIDIA MIG (Multi-Instance GPU): Divides a single GPU (A100/H100) into up to 7 hardware-isolated instances. Each instance has dedicated memory, memory controllers, and compute cores. Best for: Multi-tenant environments and medium-sized LLMs where SLA violation under load is unacceptable.
  • CUDA MPS (Multi-Process Service): Allows multiple process contexts to share a single GPU core and memory space simultaneously without context switching. Best for: High-concurrency embedding models and lightweight draft models that don't fill the entire memory bandwidth.

Step 1: Configuring the NVIDIA GPU Operator for Dynamic MIG

We deploy the NVIDIA GPU Operator using Helm, enabling the mig-parted dynamic configuration manager.

# values-gpu-operator.yaml
daemonsets:
  tolerations:
    - key: "nvidia.com/gpu"
      operator: "Exists"
      effect: "NoSchedule"

mig:
  strategy: mixed
  defaultGPUConfig: dynamic

migManager:
  enabled: true
  config:
    name: custom-mig-config

Next, we define custom MIG profiles applying spatial geometry to our A100-80GB cards. We applied a strategy dividing our 80GB GPUs into one 3g.40gb slice (for 8B parameter models) and two 2g.20gb slices (for smaller embeddings and guardrails).

# mig-config.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: custom-mig-config
  namespace: gpu-operator
data:
  config.yaml: |
    version: v1
    mig-configs:
      all-balanced:
        - device-filter: ["0x20b010de"] # A100 80GB PCIe device ID
          services:
            - name: mig-3g.40gb
              count: 1
            - name: mig-2g.20gb
              count: 2

Phase 2: Ultra-Fast Autoscaling with Karpenter

Traditional Cluster Autoscaler relies on rigid ASGs (Auto Scaling Groups), requiring separate groups for every single GPU instance type. This creates severe provisioning friction.

Karpenter solves this by evaluating pod requirements directly against AWS API capabilities, selecting the most cost-effective instance, and executing JIT provisioning.

Optimizing Provisioning Speed (The "Cold-Start" Battle)

To achieve sub-100ms inference response times even during cold scales, the underlying node must boot within 45 seconds, and the container image (vLLM image ~15GB + model weights ~16GB) must mount instantly.

We achieved this by:

  1. Custom Bottlerocket AMIs pre-loaded with NVIDIA drivers and container base layers.
  2. Local NVMe Raid 0 Scratch Storage automatically mounted for HuggingFace/vLLM cache via Karpenter initialization scripts.
  3. Container Image Pre-warming via container image streaming (spegel / peer-to-peer registry pulls).

Karpenter EC2NodeClass & NodePool Manifests

Below is the production-grade Karpenter configuration for our high-throughput GPU workloads:

# karpenter-gpu-config.yaml
apiVersion: karpenter.k8s.aws/v1beta1
kind: EC2NodeClass
metadata:
  name: gpu-nodeclass
spec:
  amiFamily: Bottlerocket
  role: "KarpenterNodeRole-Ecstaticloud"
  subnetSelectorTerms:
    - tags:
        karpenter.sh/discovery: "ecstaticloud-eks-cluster"
  securityGroupSelectorTerms:
    - tags:
        karpenter.sh/discovery: "ecstaticloud-eks-cluster"
  amiSelectorTerms:
    - name: "bottlerocket-aws-k8s-1.29-nvidia-*"
  
  # Fast NVMe ephemeral storage configuration for Model Weights Cache
  blockDeviceMappings:
    - deviceName: /dev/xvda
      ebs:
        volumeSize: 50Gi
        volumeType: gp3
        iops: 3000
        throughput: 125
    - deviceName: /dev/xvdb
      ebs:
        volumeSize: 300Gi
        volumeType: gp3
        iops: 10000
        throughput: 1000 # High throughput for fast model load from disk to VRAM

---
apiVersion: karpenter.sh/v1beta1
kind: NodePool
metadata:
  name: gpu-nodepool
spec:
  template:
    metadata:
      labels:
        workload: llm-inference
        accelerator: nvidia-gpu
    spec:
      requirements:
        - key: karpenter.sh/capacity-type
          operator: In
          values: ["on-demand", "spot"] # Fallback to spot for low-priority draft models
        - key: karpenter.k8s.aws/instance-family
          operator: In
          values: ["g5", "p4d"] # EC2 Instance types (A10G, A100)
        - key: kubernetes.io/arch
          operator: In
          values: ["amd64"]
      nodeClassRef:
        name: gpu-nodeclass
      taints:
        - key: nvidia.com/gpu
          value: "true"
          effect: NoSchedule
  
  # Resource consolidation for aggressive cost optimization
  disruption:
    consolidationPolicy: WhenEmpty
    consolidateAfter: 2m

Phase 3: High-Throughput Workload Deployment

Now, let's tie everything together with a production deployment running vLLM on top of a dynamic MIG partition (mig-3g.40gb), configured for auto-scaling via KEDA based on pending request queues.

vLLM Deployment Manifest with Dynamic Allocation

# vllm-llama3-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: vllm-llama-3-8b
  namespace: llm-serving
spec:
  replicas: 1
  selector:
    matchLabels:
      app: vllm-llama-3-8b
  template:
    metadata:
      labels:
        app: vllm-llama-3-8b
    spec:
      tolerations:
        - key: "nvidia.com/gpu"
          operator: "Exists"
          effect: "NoSchedule"
      nodeSelector:
        workload: llm-inference
      containers:
        - name: vllm-server
          image: vllm/vllm-openai:v0.4.2
          args:
            - "--model"
            - "meta-llama/Meta-Llama-3-8B-Instruct"
            - "--gpu-memory-utilization"
            - "0.90"
            - "--max-model-len"
            - "8192"
            - "--port"
            - "8000"
          env:
            - name: HUGGING_FACE_HUB_TOKEN
              valueFrom:
                secretKeyRef:
                  name: hf-token-secret
                  key: token
            - name: HF_HOME
              value: "/tmp/huggingface"
          resources:
            limits:
              cpu: "8"
              memory: "32Gi"
              # Request exact MIG slice resource exposed by GPU Operator
              nvidia.com/mig-3g.40gb: "1"
            requests:
              cpu: "4"
              memory: "16Gi"
              nvidia.com/mig-3g.40gb: "1"
          ports:
            - containerPort: 8000
              name: http
          readinessProbe:
            httpGet:
              path: /health
              port: 8000
            initialDelaySeconds: 30
            periodSeconds: 5
          volumeMounts:
            - mountPath: /tmp/huggingface
              name: model-cache
      volumes:
        - name: model-cache
          emptyDir: {}

Observability & Metrics: Proving the Efficiency Gains

To measure the success of our deployment, we tracked two critical vector dimensions in Prometheus: Compute Utilization vs. Memory Allocated and Karpenter Provisioning Latency.

DCGM Prometheus Query for Actual GPU Core Utilization

Standard nvidia-smi metrics can be misleading because VRAM reservation is often static in LLM engines (like vLLM PagedAttention holding 90% of memory upfront). We queried actual Tensor Core activity using NVIDIA Data Center GPU Manager (DCGM) metrics:

# Real Tensor Core Compute Utilization (%)
sum(rate(DCGM_FI_DEV_TENSOR_ACTIVE[1m])) by (pod, instance) 
/ 
sum(DCGM_FI_DEV_TENSOR_ACTIVE) by (pod, instance) * 100

Dynamic Slicing Benchmark Results

By combining MIG, MPS, and Karpenter fast-provisioning, we shifted our cluster performance profile dramatically:

| Metric | Legacy (Static 1-Pod-per-GPU + Cluster Autoscaler) | Optimized (MIG/MPS Slicing + Karpenter JIT) | Improvement | | :--- | :--- | :--- | :--- | | GPU Idle Time | 68% average | 23.8% average | 65% Reduction | | P95 Inference Latency | 340ms (under queue saturation) | 82ms | 75.8% Lower | | Node Provisioning Latency | 8m 45s | 42s | 92% Faster | | Monthly GPU Cloud Spend | $42,500 | $16,150 | 62% Savings |


Architectural Lessons & Edge Cases

  1. Beware of PagedAttention Memory Reservation: Engines like vLLM pre-allocate large chunks of VRAM for KV-caching. If using CUDA MPS (shared memory), explicitly cap the memory space using gpu_memory_utilization parameters in vLLM to prevent one process from invoking Out-Of-Memory (OOM) errors on adjacent containers.
  2. Handle Interruption Gracefully on Spot: When using Karpenter with AWS Spot instances for draft models, hook into Karpenter's interruption-gdb events. Drain the vLLM pod, sending an HTTP SIGTERM so running inference requests complete generation before the 2-minute instance termination window closes.
  3. NVMe Local Disks are Mandatory: Do not load 20GB+ model weights directly over EBS volumes or network S3 buckets on pod startup. Format local instance NVMe drives on node boot and use them as read-through caches for models.

Conclusion

Maximizing return on infrastructure spend for distributed LLM inference doesn't require compromising on latency SLAs. By shifting from standard static allocation to dynamic, hardware-enforced GPU partitioning with NVIDIA MIG/MPS, and tying scheduling directly to Karpenter’s fast node provisioning, you can operate a production AI backend that is both lightning-fast and financially sustainable.

Have questions about tuning your Kubernetes GPU infrastructure? Drop a comment below or reach out directly to the Ecstaticloud Architecture Team.

Need Help Scaling Cloud Infrastructure?

Partner with Ecstaticloud's boutique engineering architects to implement zero-trust architectures, optimize inference workloads, or eliminate cloud waste.

Talk to an Architect
Deep Dives

Related Technical Insights

View all →