37 lines
1.5 KiB
Markdown
37 lines
1.5 KiB
Markdown
---
|
||
title: "Horizontal Pod Autoscaler (HPA)"
|
||
type: concept
|
||
tags:
|
||
- Kubernetes
|
||
- EKS
|
||
- Autoscaling
|
||
- Pod
|
||
- Metrics
|
||
sources:
|
||
- ctp-topic-59-achieving-reliability-with-amazon-eks
|
||
- ctp-topic-64-scaling-out-with-amazon-eks
|
||
last_updated: 2026-04-28
|
||
---
|
||
|
||
## Definition
|
||
Horizontal Pod Autoscaler (HPA) 是 Kubernetes 标准的工作负载水平扩缩容机制,通过监测 Pod 的资源使用指标(CPU、内存或自定义指标)自动调整 Pod 副本数,以满足应用负载需求。
|
||
|
||
## Key Mechanisms
|
||
- **指标采集**:通过 Metrics Server 获取 CPU/内存利用率指标
|
||
- **副本计算**:基于目标阈值计算所需 Pod 副本数
|
||
- **稳定性配置**:通过 `stabilizationWindowSeconds` 和 `periodSeconds` 防止震荡(flapping)
|
||
- **自定义/外部指标**:支持通过 Custom Metrics API 和 External Metrics API 集成负载均衡器并发连接数、消息中间件队列深度等业务指标
|
||
- **Pod 级而非容器级**:当前 HPA 仅考虑 Pod 整体资源消耗,不支持容器级别的独立扩缩
|
||
|
||
## Relationship with VPA
|
||
- **HPA**:水平扩展(增加/减少 Pod 副本数)
|
||
- **VPA (Vertical Pod Autoscaler)**:垂直扩展(调整单个 Pod 的资源请求)
|
||
- 两者可互补使用:HPA 应对流量波动,VPA 优化资源分配
|
||
|
||
## Relationship with KEDA
|
||
- KEDA 可通过 **Publishes Metrics 模式** 为 HPA 供数,实现指标驱动与事件驱动的混合扩缩容
|
||
|
||
## Sources
|
||
- [[ctp-topic-59-achieving-reliability-with-amazon-eks]]
|
||
- [[ctp-topic-64-scaling-out-with-amazon-eks]]
|