Kuberneteskubernetesautoscalinghpascalingproduction-ready
Horizontal Pod Autoscaler
Kubernetes HPA configuration with CPU/memory metrics, custom metrics, scaling behavior tuning, and stabilization windows.
title: "Horizontal Pod Autoscaler" description: "Kubernetes HPA configuration with CPU/memory metrics, custom metrics, scaling behavior tuning, and stabilization windows." category: "Kubernetes" language: "yaml" tags: ["kubernetes", "autoscaling", "hpa", "scaling", "production-ready"] createdAt: "2025-01-28" updatedAt: "2025-02-18"
Overview
Kubernetes Horizontal Pod Autoscaler with multiple scaling metrics (CPU, memory, custom metrics, external metrics) and fine-tuned scaling behavior. Includes stabilization windows to prevent thrashing and asymmetric scale-up/scale-down policies.
Code
behavior:
scaleUp:
stabilizationWindowSeconds: 30
policies:
- type: Percent
value: 100
periodSeconds: 30
scaleDown:
stabilizationWindowSeconds: 300Notes
stabilizationWindowSecondsprevents rapid oscillation by requiring metrics to be sustained- Scale-up is aggressive (double in 30s) while scale-down is conservative (10% per minute)
selectPolicy: Maxfor scale-up picks the policy that adds the most podsselectPolicy: Minfor scale-down picks the policy that removes the fewest pods- Resource
requestson pods are required for CPU/memory-based HPA to calculate utilization - Custom metrics require a metrics adapter (Prometheus adapter, Datadog, etc.)