Files
data-engine/k8s/hpa.yaml
2026-04-17 17:46:13 +08:00

70 lines
2.5 KiB
YAML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Horizontal Pod Autoscaler - 水平Pod自动扩缩容配置
# 根据 CPU 和内存使用率自动调整 Pod 副本数量
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: data-engine-hpa # HPA 资源名称
namespace: default # 命名空间
spec:
# 指定要自动扩缩容的目标 Deployment
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: data-engine
# 副本数量范围
minReplicas: 1 # 最小副本数:始终保持至少 1 个 Pod 运行
maxReplicas: 10 # 最大副本数:防止无限扩容,最多扩展到 10 个 Pod
# 扩缩容触发指标(满足任一条件即触发)
metrics:
# CPU 使用率指标
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 70 # 当所有 Pod 的平均 CPU 使用率超过 70% 时触发扩容
# 内存使用率指标
- type: Resource
resource:
name: memory
target:
type: Utilization
averageUtilization: 80 # 当所有 Pod 的平均内存使用率超过 80% 时触发扩容
# 扩缩容行为策略
behavior:
# 向上扩容策略(快速响应负载增加)
scaleUp:
stabilizationWindowSeconds: 60 # 稳定窗口期60 秒内只基于最高需求决策,防止抖动
policies:
# 策略1按固定数量扩容
- type: Pods
value: 2 # 每次最多增加 2 个 Pod
periodSeconds: 60 # 每 60 秒评估一次
# 策略2按比例扩容
- type: Percent
value: 50 # 每次最多增加当前副本数的 50%
periodSeconds: 60 # 每 60 秒评估一次
selectPolicy: Max # 选择两个策略中扩容幅度更大的方式(更激进)
# 向下缩容策略(保守缩容,避免频繁波动)
scaleDown:
stabilizationWindowSeconds: 300 # 稳定窗口期300 秒5分钟比扩容更保守
policies:
# 策略1按固定数量缩容
- type: Pods
value: 1 # 每次最多减少 1 个 Pod
periodSeconds: 60 # 每 60 秒评估一次
# 策略2按比例缩容
- type: Percent
value: 25 # 每次最多减少当前副本数的 25%
periodSeconds: 60 # 每 60 秒评估一次
selectPolicy: Min # 选择两个策略中缩容幅度更小的方式(更保守)