KubeSphere HPA (Horizontal Pod Autoscaler) 配置与管理指南
前提是 安装: Metrics Server 服务:
kubesphere 安装 metrics-server : 连接
检查 Metrics Server 状态
kubectl get po -A | grep metrics-server
2. 通过 KubeSphere 控制台配置 HPA
步骤 1: 进入工作负载管理
登录 KubeSphere 控制台
选择对应的企业空间和项目
导航到 应用负载 > 工作负载
选择要配置 HPA 的工作负载(Deployment/StatefulSet)
步骤 2: 配置自动扩缩容
点击目标工作负载进入详情页面
在左侧菜单选择 弹性伸缩 选项卡
点击 创建弹性伸缩策略
配置 HPA 参数:
最小副本数: 最少运行的 Pod 数量
最大副本数: 最多允许的 Pod 数量
指标类型: CPU 使用率、内存使用率或自定义指标
目标值: 触发扩缩容的指标阈值
1. 合理设置扩缩容范围
# 推荐的配置范围
spec:
minReplicas: 2 # 确保最小可用性
maxReplicas: 20 # 避免过度扩缩容
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 60 # 合理的触发阈值
验证:
1. 使用 Apache Bench (ab)
# 在测试节点安装 ab
yum install -y httpd-tools
# 基本压测命令
ab -n 10000 -c 100 http://nginx-hpa-test/
# 持续压测命令
ab -n 1000000 -c 50 -t 300 http://nginx-hpa-test/
欢迎来撩 : 汇总all