VLM Autoscaling
This guide describes how to autoscale NVIDIA NIM for VLM using Kubernetes Horizontal Pod Autoscaler (HPA) and custom metrics.
Overview
This setup enables autoscaling of NVIDIA NIM for VLM workloads based on custom latency metrics. The system scales up when request latency degrades and scales down during low utilization optimizing resource usage while maintaining performance SLAs.
The manifests in this guide are a worked example for the
cosmos-reason1-7b NIM. If you use another VLM NIM, replace the NIM image,
model profile, Kubernetes resource names, and the service selectors in the
Prometheus queries together so that they continue to refer to the same
deployed service.
Prerequisites:
- StorageClass: Kubernetes cluster must be provisioned with a StorageClass that supports “ReadWriteMany”
- Prometheus: An existing Prometheus service that scrapes the NIM metrics
- Prometheus Adapter: Exposes custom Prometheus metrics to Kubernetes HPA. Installation instructions provided below
- HPA: Natively supported by Kubernetes and automatically scales NIM service pods based on custom metrics
- NIM Operator: Deploys the NVIDIA NIM for VLM microservice. Follow instructions to install NIM operator cluster wide
1. Persistent Volume Setup
1.1 Create Persistent Volume
Create a manifest file pv-nim-cache.yaml:
Apply the PV:
Verify PV creation:
Expected output:
1.2 Create Persistent Volume Claim (PVC)
Create a manifest file pvc-nim-cache.yaml:
Apply the PVC:
Verify PVC is bound:
Expected output:
1.3 Create NIM Cache Using PVC
Once the PVC is bound, create a NIMCache resource to load model weights on the shared volume. This step downloads the model weights once and makes it available to all NIM pods. Visit NIM operator github for detailed description on custom resources provided by the operator.
Create required NGC secrets for pulling model files and NGC hosted containers:
Create a manifest file nim_cache.yaml:
Configuration Breakdown:
Apply the NIMCache resource:
Monitor the cache creation progress:
Wait for the NIMCache to reach Ready status. This may take 10-30 minutes depending on model size and network speed.
Expected output when ready:
Once the NIMCache is ready, the model weights are stored in the volume and available for all NIM pods to use.
2. Prometheus Adapter Installation and Configuration
The Prometheus Adapter exposes custom Prometheus metrics to Kubernetes, enabling HPA to scale based on application-specific metrics like request latency.
2.1 Install Prometheus Adapter
If not already installed, deploy Prometheus Adapter using Helm. First identify the namespace, service name, and port of the Prometheus instance that scrapes the NIM metrics:
Verify installation:
2.2 Configure Custom Metrics
The NVIDIA NIM for VLM exposes a Prometheus endpoint with many metrics. The custom metric e2e_request_latency_seconds_over_1s_fraction calculates the percentage of requests taking over 1 second measured every minutes and is created in the PromQL formula below that uses the “e2e_request_latency_seconds_bucket” histogram exposed by the NVIDIA NIM for VLM Prometheus endpoint.
Metric Formula:
Create or update the ConfigMap:
Configuration Breakdown:
-
seriesQuery: Identifies the Prometheus metric to query (
e2e_request_latency_seconds_count) -
resources.overrides: Maps Prometheus labels to Kubernetes resources
-
name.as: Defines the custom metric name exposed to Kubernetes
-
metricsQuery: PromQL query that calculates the latency fraction
- Numerator: Requests that took > 1 second
- Denominator: Total requests (+ 0.0001 to avoid division by zero)
[1m]: 1-minute window for rate calculation
2.3 Restart Prometheus Adapter
After updating the ConfigMap, restart the adapter:
2.4 Verify Custom Metrics
Check if the custom metric is available:
Query the specific metric:
Expected output:
3. NIM Service with HPA Configuration
The NIMService custom resource combines the NIM deployment with HPA configuration.
3.1 Create NGC Secrets
Create secrets for pulling NIM images if not done in the previous step:
3.2 Deploy NIM Service with HPA
Create nimservice-cosmos-reason1-7b.yaml, note the configuration below uses the H100 profile:
Configuration Highlights:
HPA Metrics:
- Threshold:
400m(0.4 or 40%) - Interpretation: Scale up when 40% or more requests exceed 1 second latency
- Type: Object metric (tied to the Service resource)
Scale Up Behavior:
- Immediate: No stabilization window (fast response to load)
- Aggressive: Add 3 pods per scaling event
- Frequency: Check every 15 seconds
Scale Down Behavior:
- Conservative: 3-minute observation period (prevents flapping)
- Gradual: Remove max 50% of pods per event
- Slow: Check every 2 minutes
- Safe: Always choose the policy that removes fewer pods
The Scale UP and Scale Down scenarios and HPA configuration should be tuned based on your specific traffic patterns and use case requirements. The values shown above are examples and may need adjustment for:
- Bursty vs. steady traffic: Aggressive scale-up for sudden spikes vs. gradual scaling for predictable growth
- SLA requirements: Stricter latency targets may require more aggressive scaling policies
- Pod startup time: Longer initialization times may need earlier/faster scale-up triggers
3.3 Deploy the NIM Service
Verify deployment:
3.4 Monitor HPA Status
View detailed HPA information:
Expected output:
4. Testing and Monitoring HPA Scaling
4.1 Generate Load using genai-perf
4.1 Generate Load using genai-perf
Now you can send traffic to your NIM VLM microservice and watch HPA increase and decrease replicas. For synthetic traffic generation use genai-perf.
4.2 Monitor Scaling Events
Watch HPA behavior in real-time:
kubectl get hpa -n vlm -w- Watch HPA statuskubectl get pods -n vlm- Monitor pod countkubectl get events -n vlm- View scaling events
4.3 Test Scaling Scenarios
Verify HPA behavior under different load patterns:
- Gradual increase: Ensure smooth scale-up as load grows
- Sudden spike: Test rapid scale-up capability
- Load decrease: Verify proper scale-down with stabilization