| 指标 | 队列深度与并发数通常比 CPU 更贴近服务负载 |
|---|---|
| 节奏 | 冷却时间防抖动;步长兼顾快速响应与成本 |
| 准备 | 镜像与依赖预热,缩短新实例可用时间 |
HPA 示例(按队列深度扩容)
HPA 示例(按队列深度扩容)
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: order-worker
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: order-worker
minReplicas: 2
maxReplicas: 20
metrics:
- type: Pods
pods:
metric:
name: queue_depth
target:
type: AverageValue
averageValue: "50"
behavior:
scaleUp:
stabilizationWindowSeconds: 60
scaleDown:
stabilizationWindowSeconds: 300- 实测扩容时延:从指标越阈到实例可服务,要小于流量爬升时间
- 为依赖方(数据库、第三方配额)设伸缩上限,防止连带打满
伸缩主要调整无状态层:数据库与会话层的容量瓶颈要靠架构与预案解决。