| 对象 | HorizontalPodAutoscaler,scaleTargetRef 指向 Deployment 等 |
|---|---|
| CPU 指标 | utilization 相对 requests 的百分比;必须设 resources.requests |
| 副本范围 | minReplicas / maxReplicas;默认 1-10 |
| 行为 | behavior 控制扩容/缩容速度与稳定窗口 |
| 前置 | metrics-server(资源指标);自定义指标要 adapter |
HPA 示例
HPA 示例
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: web
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: web
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70
HPA 扩的是副本数、不是节点数:集群节点容量不够扩出来的 Pod 会 Pending,需配合 Cluster Autoscaler 等。