ai-gpu-infra-llmops
Deploys and scales production AI/LLM and GPU infrastructure in Kubernetes using NVIDIA GPU Operator, DRA/MIG, vLLM tensor parallelism, KEDA scale-to-zero, Karpenter GPU nodes, Envoy AI Gateway, and LiteLLM. Use for self-hosted LLM serving and token cost governance.
AI/GPU Infrastructure & LLMOps in Kubernetes
High-throughput vLLM GPU serving, MIG/DRA hardware partitioning, KEDA scale-to-zero, and LiteLLM/Envoy AI Gateway routing.
Quick Start
# Deploy vLLM multi-GPU inference server and LiteLLM AI Gateway in Kubernetes
kubectl apply -f labs/nextgen_2027_pack/k8s-gpu-vllm-inference.yaml
kubectl apply -f labs/nextgen_2027_pack/envoy-ai-gateway-litellm.yaml# Shared memory /dev/shm volume required for multi-GPU PyTorch NCCL tensor parallelism
volumes:
- name: dshm
emptyDir:
medium: Memory
sizeLimit: 16GiWhen to Use
- Running open-weights LLMs (Qwen, Llama, DeepSeek, Mistral) on NVIDIA GPUs in Kubernetes with vLLM continuous batching and PagedAttention
- Partitioning A100/H100 GPUs via Multi-Instance GPU (MIG), Dynamic Resource Allocation (DRA), or Time-Slicing
- Scaling idle GPU inference pods down to zero with KEDA and provisioning spot/on-demand GPU nodes with Karpenter
- Routing, rate-limiting by tokens, semantic caching, and setting per-team budgets across local vLLM and cloud APIs via LiteLLM or Envoy AI Gateway
Best Practices
- Always mount an in-memory emptyDir (medium: Memory, sizeLimit: 16Gi) at /dev/shm when tensor-parallel-size >= 2 so NCCL never crashes on Linux's default 64MB shm.
- Store HuggingFace model weights on a persistent PVC or pre-baked node snapshot so pod restarts do not re-download 60GB+ weights over the network.
- Enable --enable-prefix-caching and tune --gpu-memory-utilization 0.92 in vLLM to maximize KV-cache throughput for system prompts.
- Use hardware MIG profiles in production for strict VRAM/compute isolation and Time-Slicing only in non-critical dev/staging clusters.
- Place LiteLLM or Envoy AI Gateway in front of all model endpoints to enforce token-per-minute limits, budget caps, and automatic cloud failover.
- Enable Redis semantic caching on the AI Gateway to serve repeated or near-identical prompts in <15ms at zero GPU compute cost.
Dependencies
# Install NVIDIA GPU Operator via Helm in Kubernetes
helm repo add nvidia https://helm.ngc.nvidia.com/nvidia && helm repo update
helm install gpu-operator nvidia/gpu-operator -n gpu-operator --create-namespaceExamples
# Estimate vLLM VRAM requirement (GB) for FP16/BF16 vs AWQ/GPTQ 4-bit quantization with KV cache overhead
def estimate_vram_gb(params_b: float, bits: int = 16, kv_overhead: float = 1.25) -> float:
bytes_per_param = bits / 8.0
return round(params_b * bytes_per_param * kv_overhead, 2)
assert estimate_vram_gb(32, bits=16) == 80.0
assert estimate_vram_gb(32, bits=4) == 20.0# LiteLLM Gateway configuration with local vLLM primary, Claude fallback, and Redis semantic cache
model_list:
- model_name: coding-assistant
litellm_params:
model: openai/Qwen/Qwen2.5-Coder-32B-Instruct
api_base: http://vllm-inference-svc.ai-inference.svc:8000/v1
api_key: internal-k8s-key
litellm_settings:
fallbacks: [{"coding-assistant": ["claude-sonnet-fallback"]}]
cache: true
cache_params:
type: redis-semanticStep-by-Step
1. Deploy NVIDIA GPU Operator in Kubernetes and verify nvidia.com/gpu allocatable resources on GPU worker nodes.
2. Configure Karpenter NodePool with node.kubernetes.io/instance-type GPU families and consolidation policies.
3. Create a PersistentVolumeClaim for /root/.cache/huggingface and an in-memory emptyDir volume for /dev/shm.
4. Deploy vLLM with --tensor-parallel-size, --max-model-len, --enable-prefix-caching, and readiness probes on /health.
5. Configure a KEDA ScaledObject watching vllm:num_requests_waiting in Prometheus to scale GPU replicas between 0/1 and N.
6. Deploy LiteLLM / Envoy AI Gateway with virtual keys, per-team max_budget limits, and Redis semantic caching.
7. Monitor time-to-first-token (TTFT), inter-token latency (ITL), KV-cache usage, and GPU DCGM temperature/power metrics in Grafana.
Validation
1. kubectl get nodes -o json confirms allocatable nvidia.com/gpu capacity on GPU nodes
2. vLLM /v1/chat/completions responds with streaming tokens and prefix-cache hit rate > 0%
3. LiteLLM gateway enforces token rate limits and seamlessly fails over when primary vLLM pod is cordoned
4. Prometheus scrapes both vLLM queue metrics and NVIDIA DCGM GPU utilization metrics
Troubleshooting
- PyTorch NCCL error: unhandled system error / shm exhausted — mount emptyDir with medium: Memory and sizeLimit: 16Gi at /dev/shm.
- vLLM pod killed by livenessProbe during weight loading — add a startupProbe allowing up to 10 minutes (failureThreshold: 60, periodSeconds: 10).
- CUDA OutOfMemoryError on startup — lower --max-model-len or use AWQ/FP8 quantized weights to leave headroom for the KV cache.
- GPU pod stuck in Pending — ensure spec.tolerations includes key: nvidia.com/gpu, operator: Exists, effect: NoSchedule.
AI/GPU Infrastructure & LLMOps in Kubernetes (Сервинг LLM и GPU в K8s)
Высокопроизводительный сервинг LLM через vLLM на GPU в Kubernetes, разделение карт MIG/DRA, автоскейлинг KEDA и шлюз LiteLLM.
Быстрый старт
# Deploy vLLM multi-GPU inference server and LiteLLM AI Gateway in Kubernetes
kubectl apply -f labs/nextgen_2027_pack/k8s-gpu-vllm-inference.yaml
kubectl apply -f labs/nextgen_2027_pack/envoy-ai-gateway-litellm.yaml# Shared memory /dev/shm volume required for multi-GPU PyTorch NCCL tensor parallelism
volumes:
- name: dshm
emptyDir:
medium: Memory
sizeLimit: 16GiКогда использовать
- Запуск локальных LLM (Qwen, Llama, DeepSeek, Mistral) на картах NVIDIA в Kubernetes через движок vLLM (PagedAttention, Continuous Batching)
- Аппаратная нарезка дорогих GPU A100/H100 через профили MIG, драйверы DRA или разделение времени Time-Slicing
- Масштабирование простаивающих GPU-подов в ноль через KEDA и быстрый заказ GPU-нод через Karpenter
- Единый шлюз LiteLLM / Envoy AI Gateway для учета токенов, бюджетов по командам, семантического кэша в Redis и фоллбэка в облачные API
Лучшие практики
- Обязательно монтируйте emptyDir в RAM (medium: Memory, sizeLimit: 16Gi) в /dev/shm при tensor-parallel-size >= 2, иначе PyTorch NCCL упадет из-за лимита в 64 МБ.
- Кэшируйте веса моделей HuggingFace на постоянном томе PVC или локальном NVMe, чтобы при рестарте пода не качать по 60+ ГБ из сети.
- Включайте --enable-prefix-caching и --gpu-memory-utilization 0.92 в vLLM для переиспользования KV-кэша системных промптов.
- Применяйте аппаратный MIG в продакшене для жесткой изоляции видеопамяти, а Time-Slicing — только для тестовых и dev-стендов.
- Ставьте шлюз LiteLLM / Envoy AI Gateway перед всеми LLM для лимитирования токенов в минуту, контроля бюджетов и автопереключения при сбоях.
- Включайте семантический кэш в Redis/Valkey на уровне AI-шлюза, чтобы отдавать типовые ответы за 15 мс без нагрузки на GPU.
Зависимости
# Install NVIDIA GPU Operator via Helm in Kubernetes
helm repo add nvidia https://helm.ngc.nvidia.com/nvidia && helm repo update
helm install gpu-operator nvidia/gpu-operator -n gpu-operator --create-namespaceПримеры
# Estimate vLLM VRAM requirement (GB) for FP16/BF16 vs AWQ/GPTQ 4-bit quantization with KV cache overhead
def estimate_vram_gb(params_b: float, bits: int = 16, kv_overhead: float = 1.25) -> float:
bytes_per_param = bits / 8.0
return round(params_b * bytes_per_param * kv_overhead, 2)
assert estimate_vram_gb(32, bits=16) == 80.0
assert estimate_vram_gb(32, bits=4) == 20.0# LiteLLM Gateway configuration with local vLLM primary, Claude fallback, and Redis semantic cache
model_list:
- model_name: coding-assistant
litellm_params:
model: openai/Qwen/Qwen2.5-Coder-32B-Instruct
api_base: http://vllm-inference-svc.ai-inference.svc:8000/v1
api_key: internal-k8s-key
litellm_settings:
fallbacks: [{"coding-assistant": ["claude-sonnet-fallback"]}]
cache: true
cache_params:
type: redis-semanticПошаговое руководство
1. Установите NVIDIA GPU Operator в кластер и проверьте появление ресурсов nvidia.com/gpu в описании GPU-узлов.
2. Опишите Karpenter NodePool с фильтрацией по GPU-инстансам, толерациями nvidia.com/gpu и политикой консолидации.
3. Создайте том PVC для кэша весов /root/.cache/huggingface и том emptyDir в памяти (Memory) для /dev/shm.
4. Разверните Deployment с vLLM, указав --tensor-parallel-size, --max-model-len, --enable-prefix-caching и пробу готовности /health.
5. Настройте KEDA ScaledObject по метрике очереди запросов vllm:num_requests_waiting для автоскейлинга реплик.
6. Поднимите шлюз LiteLLM / Envoy AI Gateway с виртуальными ключами команд, лимитами бюджетов и семантическим кэшем в Redis.
7. Выведите на дашборд Grafana метрики TTFT (время первого токена), заполнение KV-cache и телеметрию карт DCGM Exporter.
Валидация
1. Узлы кластера отображают доступные ресурсы nvidia.com/gpu в выводе kubectl describe node
2. Эндпоинт vLLM /v1/chat/completions отдает поток токенов и фиксирует попадания в prefix-cache
3. Шлюз LiteLLM контролирует квоты токенов и прозрачно переключает запросы на резервную модель при остановке пода vLLM
4. В Prometheus поступают метрики очереди vLLM и аппаратная телеметрия видеокарт из DCGM Exporter
Устранение неполадок
- Ошибка PyTorch NCCL: unhandled system error при старте на нескольких GPU — примонтируйте emptyDir (medium: Memory, 16Gi) в /dev/shm.
- Под vLLM перезапускается во время загрузки тяжелых весов — добавьте startupProbe с запасом до 10 минут (failureThreshold: 60, periodSeconds: 10).
- Ошибка CUDA OutOfMemoryError при инициализации KV-кэша — уменьшите --max-model-len или перейдите на квантованные веса AWQ/FP8.
- GPU-под висит в статусе Pending — проверьте наличие toleration для ключа nvidia.com/gpu:NoSchedule в манифесте пода.