Deploying Open-Source LLMs on Kubernetes with KServe
Deploying Large Language Models (LLMs) in production requires more than a standard web server. You need high-throughput inference engines, dynamic GPU resource allocation, scale-to-zero autoscaling, and robust health monitoring.
Enter KServe. Built on top of Kubernetes and Knative, KServe provides a standardized, Kubernetes-native abstraction layer for serving machine learning models at scale, making it the premier choice for deploying open-source models using engines like vLLM and Triton Inference Server.
Architecture of KServe with vLLM
KServe handles the heavy lifting of cluster orchestration, networking, and request routing, while backend serving runtimes handle raw model execution:
- InferenceService Custom Resource: A declarative Kubernetes CRD that defines your model repository, storage URI (e.g., S3 or Hugging Face), and hardware resource limits (GPUs/CPUs).
- vLLM Serving Runtime: Acts as the high-performance inference engine, utilizing PagedAttention to maximize GPU memory throughput and reduce latency.
- Knative Serving Layer: Manages serverless autoscaling—automatically scaling your pods up under high concurrency and down to zero when idle to save GPU costs.
Traditional Docker Deployments vs. KServe on Kubernetes
| Feature | Standard Docker / FastAPI | KServe on Kubernetes |
|---|---|---|
| Autoscaling | Manual or basic CPU-based HPA | Native request-based and scale-to-zero autoscaling |
| GPU Management | Manual container runtime configuration | Automated NVIDIA GPU device plugin scheduling |
| Inference Optimization | Requires custom batching and memory management | Integrated high-performance engines (vLLM, Triton) |
| Traffic Management | Requires manual NGINX/Envoy setup | Built-in canary rollouts and traffic splitting |
Deploying an InferenceService Manifest
Once KServe is installed on your Kubernetes cluster, deploying an open-source model like Llama 3 via vLLM requires a simple YAML manifest:
apiVersion: "serving.kserve.io/v1beta1"
kind: "InferenceService"
metadata:
name: "llama-3-8b"
spec:
predictor:
model:
modelFormat:
name: pytorch
runtime: kserve-vllm
storageUri: "gs://your-model-bucket/llama-3-8b"
resources:
limits:
cpu: "8"
memory: 32Gi
nvidia.com/gpu: "1"
requests:
cpu: "4"
memory: 16Gi
nvidia.com/gpu: "1"
Production Best Practices
Running LLMs on Kubernetes at scale requires careful tuning of cluster infrastructure and autoscaling policies:
- Tune vLLM Tensor Parallelism: Match your
--tensor-parallel-sizeargument to the exact number of GPUs allocated per pod (e.g., 2 GPUs for multi-card nodes). - Configure Scale-to-Zero Wisely: Avoid scale-to-zero for latency-critical production endpoints, as cold-starting large model weights into VRAM can introduce multi-minute delays.
- Monitor GPU Metrics: Integrate Prometheus and the DCGM (Data Center GPU Manager) exporter to track VRAM utilization, temperature, and thermal throttling in real time.