K8s by Example: Horizontal Pod Autoscaler
| HPA scales Pods based on CPU, memory, or custom metrics. Requires metrics-server in the cluster. Adjusts replicas to maintain target utilization automatically. |
| hpa.yaml | |
| HPA uses the | |
| pod-resources.yaml | |
| HPA calculates utilization as current/request. Requires resource requests to be defined. Without requests, HPA cannot determine utilization percentage. | |
| hpa-multi-metric.yaml | |
| Combine CPU and memory metrics. HPA takes the max of calculated replicas from all metrics. Good for workloads that are both CPU and memory bound. | |
| hpa-behavior.yaml | |
| Control scaling behavior: scale up fast, down slow. | |
| hpa-custom.yaml | |
| Custom metrics from Prometheus or other sources. Requires metrics adapter (prometheus-adapter, KEDA). Scale on queue depth, requests per second, or any application metric. | |
| hpa-external.yaml | |
| External metrics come from outside the cluster (cloud monitoring, SaaS). Scale based on SQS queue length, Pub/Sub backlog, or any external data source. Requires external metrics provider like KEDA. | |
| hpa-targets.yaml | |
| HPA works with Deployments, StatefulSets, and ReplicaSets. Cannot scale DaemonSets (1 per node by design). It conflicts with manual scaling because HPA overwrites manual replica changes. | |
| terminal | |
| Debug HPA by checking events, current metrics, and conditions. Common issues: metrics-server not running, missing resource requests, invalid metric names. TARGETS shows current/target utilization. | |