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

Slashing LLM Inference Costs: Dynamic GPU Autoscaling on AWS EKS with Karpenter

As enterprise Generative AI workloads surge, managing GPU provisioning costs while maintaining low-latency inference has become a critical engineering challenge. Learn how to leverage Karpenter's just-in-time node provisioning to dynamically scale heterogeneous GPU pools on EKS for high-performance, cost-optimized model serving.

Deploying Large Language Models (LLMs) such as Llama-3-70B, Mixtral-8x7B, or Falcon in production presents a brutal trade-off: high availability and low-latency response requirements demand warm compute capacity, while modern high-performance GPUs (NVIDIA A10G, L4, A100, H100) carry massive hourly price tags.

Running static GPU clusters guarantees high idle overhead during off-peak hours. Conversely, traditional autoscaling approaches fail to meet SLA requirements because spinning up GPU instances, pull-loading 40GB+ container images, and mounting massive model weights can easily lead to 10-15 minute cold-start penalties.

To solve this, modern Cloud Infrastructure engineering demands a declarative, high-frequency, just-in-time provisioning engine. In this post, we will build an enterprise-grade GPU autoscaling architecture on AWS EKS using Karpenter, targeting dynamic heterogeneous GPU pools, sub-minute instance provisioning, and automated cost consolidation.


The Failure of Traditional Autoscaling for GPU Workloads

Historically, platform teams relied on the Kubernetes Cluster Autoscaler (CAS) paired with AWS Auto Scaling Groups (ASGs). When scaling CPU-bound web services, CAS is manageable. When scaling GPU-accelerated LLM inference pipelines, CAS falls apart due to fundamental structural limitations:

  1. Rigid ASG Abstractions: CAS scales Node Groups. If you define an ASG of g5.2xlarge instances and run out of AWS Spot capacity in a specific Availability Zone, CAS cannot dynamically switch execution to a g6.2xlarge or p4d.24xlarge without pre-configured, duplicate Node Groups.
  2. Ignorance of Hardware Primitives: CAS does not inspect pod requirements such as GPU memory overhead, NVMe instance store availability, or CUDA capability requirements directly against raw EC2 API capabilities.
  3. Slow Scale-Up Cycles: CAS evaluates pending pods, modifies ASG desired capacity, waits for the ASG to invoke the EC2 Launch Template, and then waits for the node to register. This multi-layered abstraction adds minutes to provisioning pipelines.
  4. Sub-optimal Bin-packing and Disruption: De-provisioning GPU nodes safely without interrupting active inferencing streams requires intelligent node consolidation—something standard CAS scale-down logic lacks when dealing with heterogeneous compute costs.

Architecture Overview: Karpenter Just-In-Time Provisioning

Karpenter bypasses the Auto Scaling Group abstraction entirely. It operates by observing unschedulable pods, evaluating their constraints (tolerations, node selectors, resource requests, volume claims), directly calling the AWS EC2 Fleet API, and launching the precise EC2 instance tailored to the incoming workload within seconds.

+-----------------------------------------------------------------------+
|                             AWS EKS CLUSTER                           |
|                                                                       |
|  +--------------------+       +------------------------------------+  |
|  | Unscheduled Pod    | ----> | Karpenter Controller               |  |
|  | (vLLM / Triton)    |       | (Observes Pending Pod Specs)       |  |
|  +--------------------+       +------------------------------------+  |
+---------------------------------------------------|-------------------+
                                                    | Direct EC2 Fleet API
                                                    v
+-----------------------------------------------------------------------+
|                             AWS EC2 FLEET                             |
|                                                                       |
|  +-------------------+  +-------------------+  +-------------------+  |
|  | g5.2xlarge (Spot) |  | g6.xlarge (Spot)  |  | p4d.24xlarge (OD) |  |
|  | (1x NVIDIA A10G)  |  | (1x NVIDIA L4)    |  | (8x NVIDIA A100)  |  |
|  +-------------------+  +-------------------+  +-------------------+  |
+-----------------------------------------------------------------------+

Key Architectural Advantages for LLMs:

  • Heterogeneous Instance Selection: A single Karpenter NodePool can target dozens of GPU instance types (g5.*, g6.*, p4d.*, p5.*). Karpenter dynamically chooses the cheapest instance type available in the requested Availability Zone.
  • Spot Instance Prioritization with On-Demand Fallback: Effortlessly fallback from Spot to On-Demand capacity when GPU spot pools face constraints.
  • Ephemeral Storage Initialization: Automatically leverage fast local NVMe Instance Storage (standard on g5 and p4 families) to store HuggingFace or S3 cached model weights, bypassing EBS throughput bottlenecks.

Infrastructure Blueprint: Setting Up Karpenter GPU Pools

Let's dive into the production-ready YAML manifests required to configure Karpenter (v1.x+) for high-density, low-latency GPU node management on EKS.

1. Defining the EC2NodeClass

The EC2NodeClass abstracts the AWS-specific configuration (AMIs, IAM roles, Security Groups, Subnets, and Storage Mappings).

For GPU workloads, we must configure:

  • NVIDIA AL2 GPU EKS Optimized AMI (or Bottlerocket GPU).
  • RAID 0 / Block Device Mapping to format local ephemeral NVMe drives for fast model weight caching.
apiVersion: karpenter.k8s.aws/v1
kind: EC2NodeClass
metadata:
  name: gpu-ec2nodeclass
spec:
  amiFamily: AL2
  amiSelectorTerms:
    - name: "amazon-eks-gpu-node-1.30-*"
  role: "KarpenterNodeRole-eks-cluster-prod"
  subnetSelectorTerms:
    - tags:
        karpenter.sh/discovery: "eks-cluster-prod"
  securityGroupSelectorTerms:
    - tags:
        karpenter.sh/discovery: "eks-cluster-prod"
  
  # Configure root volume for deep model image layers
  blockDeviceMappings:
    - deviceName: /dev/xvda
      ebs:
        volumeSize: 150Gi
        volumeType: gp3
        iops: 5000
        throughput: 250
        encrypted: true

  # Pre-mount local NVMe instance store for high-speed model weight caching
  userData: |
    #!/bin/bash
    set -o errexit
    set -o pipefail
    set -o nounset

    # Format and mount local ephemeral NVMe SSD if present (e.g., g5/g6 instances)
    if ls /dev/nvme*n1 1>/dev/null 2>&1; then
      ephemeral_dev=$(ls /dev/nvme*n1 | head -n 1)
      if ! file -s $ephemeral_dev | grep -q filesystem; then
        mkfs.ext4 -m 0 -E lazy_itable_init=0,lazy_journal_init=0 $ephemeral_dev
      fi
      mkdir -p /mnt/k8s-disks/by-name/ephemeral-gpu-cache
      mount -o defaults,noatime,nodiratime $ephemeral_dev /mnt/k8s-disks/by-name/ephemeral-gpu-cache
      chmod 0777 /mnt/k8s-disks/by-name/ephemeral-gpu-cache
    fi

2. Defining the High-Performance NodePool

The NodePool sets constraints on what types of EC2 instances Karpenter can launch, capacity types (Spot vs. On-Demand), and node disruption policies.

apiVersion: karpenter.sh/v1
kind: NodePool
metadata:
  name: gpu-llm-nodepool
spec:
  template:
    metadata:
      labels:
        workload: llm-inference
        accelerator: nvidia
    spec:
      nodeClassRef:
        group: karpenter.k8s.aws
        kind: EC2NodeClass
        name: gpu-ec2nodeclass
      requirements:
        # Flexible architecture targeting cost-efficient and high-tier GPUs
        - key: karpenter.k8s.aws/instance-family
          operator: In
          values: ["g5", "g6", "p4d"]
        - key: karpenter.k8s.aws/instance-size
          operator: In
          values: ["xlarge", "2xlarge", "12xlarge", "24xlarge"]
        - key: karpenter.sh/capacity-type
          operator: In
          values: ["spot", "on-demand"]
        - key: kubernetes.io/arch
          operator: In
          values: ["amd64"]
      taints:
        - key: nvidia.com/gpu
          value: "true"
          effect: NoSchedule

  # Resource caps to control maximum cluster budget spend
  limits:
    nvidia.com/gpu: "64"

  # Dynamic consolidation rules for immediate cost slashing
  disruption:
    consolidationPolicy: WhenEmptyOrUnderutilized
    consolidateAfter: 2m
    budgets:
      - nodes: "20%" # Prevent massive batch terminations during high traffic

Latency Optimization: Eliminating GPU Cold-Start Bottlenecks

Spinning up the GPU instance with Karpenter takes less than 45 seconds. However, loading an LLM into GPU memory can take 5+ minutes if not properly architected. To optimize latency:

Strategy 1: HostPath Volume Mount to NVMe Cache

Instead of pulling model weights directly from S3 or HuggingFace on every pod lifecycle event, leverage the instance-store path initialized in our EC2NodeClass user data.

Here is an optimized deployment running vLLM serving standard Meta-Llama-3-8B-Instruct.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: vllm-llama-3-8b
  namespace: llm-serving
spec:
  replicas: 2
  selector:
    matchLabels:
      app: vllm-llama-3-8b
  template:
    metadata:
      labels:
        app: vllm-llama-3-8b
        workload: llm-inference
    spec:
      # Match the taints and requirements of our Karpenter GPU NodePool
      tolerations:
        - key: "nvidia.com/gpu"
          operator: "Equal"
          value: "true"
          effect: "NoSchedule"
      nodeSelector:
        workload: llm-inference
        accelerator: nvidia
      containers:
        - name: vllm-engine
          image: vllm/vllm-openai:v0.5.4
          args:
            - "--model"
            - "meta-llama/Meta-Llama-3-8B-Instruct"
            - "--tensor-parallel-size"
            - "1"
            - "--gpu-memory-utilization"
            - "0.90"
            - "--max-model-len"
            - "8192"
          resources:
            limits:
              nvidia.com/gpu: "1"
              memory: "32Gi"
              cpu: "4"
            requests:
              nvidia.com/gpu: "1"
              memory: "24Gi"
              cpu: "3"
          ports:
            - containerPort: 8000
          volumeMounts:
            - mountPath: /root/.cache/huggingface
              name: model-cache
            - mountPath: /dev/shm
              name: dshm
          env:
            - name: HUGGING_FACE_HUB_TOKEN
              valueFrom:
                secretKeyRef:
                  name: hf-secret
                  key: token
      volumes:
        # High throughput local NVMe mounted from Karpenter node provisioning
        - name: model-cache
          hostPath:
            path: /mnt/k8s-disks/by-name/ephemeral-gpu-cache
            type: DirectoryOrCreate
        # Shared memory required for PyTorch/vLLM IPC communication
        - name: dshm
          emptyDir:
            medium: Memory
            sizeLimit: 8Gi

Advanced Resiliency: Spot Interruption & Disruption Engineering

Running GPU inference on Spot instances slashes costs by up to 60-70% compared to On-Demand prices. However, AWS can reclaim Spot instances with a 2-minute warning.

Karpenter solves this natively when configured alongside an AWS EventBridge + SQS pipeline:

[AWS EC2 Spot Rebalance / Interruption Event]
                        |
                        v
               [AWS EventBridge]
                        |
                        v
             [AWS SQS Interruption Queue]
                        |
                        v
          [Karpenter Controller Daemon]
                        |
       +----------------+----------------+
       |                                 |
       v                                 v
[Cordon Node & Start          [Gracefully Terminate Pod
 Graceful Eviction]            After Active Requests Clear]

How to configure Spot Resiliency:

  1. Native Interruption Handling: Karpenter watches an SQS queue populated by EventBridge events for EC2 Spot Instance Interruptions, Instance State Change Notification, and Rebalance Recommendations.
  2. Graceful Drain: Upon receiving an interruption signal, Karpenter immediately cordons the affected GPU node, blocking incoming inference routes via Kubernetes Endpoints/KEDA, and triggers an immediate replacement node before the instance is reclaimed.
  3. Fallback Strategy: If Spot capacity for a specific instance type (e.g., g5.2xlarge) is depleted across all AZs, Karpenter automatically falls back to alternative families (g6.2xlarge) or On-Demand pricing as governed by the NodePool capacity rules.

Real-World Impact & Cost Analysis

Below is an architectural performance comparison observed across production GenAI cluster deployments after migrating from standard EKS Autoscaler (ASGs) to Karpenter dynamic GPU pools:

| Metric | Legacy ASG + Cluster Autoscaler | AWS EKS + Karpenter GPU Pools | Realized Optimization | | :--- | :--- | :--- | :--- | | Node Provisioning Latency | 4 - 8 Minutes | 45 - 75 Seconds | ~80% Reduction | | Fleet Bin-packing Density | Static (1 Node per ASG type) | Dynamic (Multi-GPU/Shared Instances) | 35% Higher Compute Utilization | | Spot Instance Coverage | Hard to maintain across AZs | Automated Multi-Family Fallback | Scaled from 20% to 75% Spot usage | | Average Monthly GPU Spend | baseline ($10,000/mo) | Optimized ($3,600/mo) | 64% Cost Reduction |


Architectural Takeaways

Deploying modern GenAI capabilities at scale does not require accepting astronomical infrastructure bills. By combining AWS EKS, vLLM, and Karpenter:

  1. Abandon Node Groups: Transition to declarative NodePool topologies that treat GPU types as dynamic compute resources.
  2. Optimize Ephemeral Storage: Leverage raw NVMe instance stores initialized via EC2NodeClass user data to optimize LLM weight hydration paths.
  3. Architect for Disruption: Embrace AWS Spot capacity by leveraging native SQS interruption events in Karpenter to gain high resilience at low costs.

By applying these patterns, platform engineering teams can achieve high-frequency dynamic scaling, near-instantaneous provisioning times, and dramatic cost savings for enterprise Generative AI deployments.

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 →