7.11. 使用 pod 横向自动扩展 HPA 自动扩展 pod
使用 EAP 操作器时,您可以使用 pod 横向自动扩展 HPA 根据从属于该 EAP 应用的容器集收集的指标来自动增加或减少 EAP 应用规模。
注意
使用 HPA 确保 pod 缩减时仍然会处理事务恢复。
流程
配置资源:
apiVersion: wildfly.org/v1alpha1 kind: WildFlyServer metadata: name: eap-helloworld spec: applicationImage: 'eap-helloworld:latest' replicas: 1 resources: limits: cpu: 500m memory: 2Gi requests: cpu: 100m memory: 1Gi重要您必须指定 pod 中的容器的资源限值和请求,以便自动扩展才能按预期工作。
创建 Horizontal pod 自动缩放器:
oc autoscale wildflyserver/eap-helloworld --cpu-percent=50 --min=1 --max=10
验证
- 您可以通过检查副本来验证 HPA 行为。根据工作负载的增加或减少,副本数增加或降低。
oc get hpa -w
NAME REFERENCE TARGETS MINPODS MAXPODS REPLICAS AGE
eap-helloworld WildFlyServer/eap-helloworld 217%/50% 1 10 1 4s
eap-helloworld WildFlyServer/eap-helloworld 217%/50% 1 10 4 17s
eap-helloworld WildFlyServer/eap-helloworld 133%/50% 1 10 8 32s
eap-helloworld WildFlyServer/eap-helloworld 133%/50% 1 10 10 47s
eap-helloworld WildFlyServer/eap-helloworld 139%/50% 1 10 10 62s
eap-helloworld WildFlyServer/eap-helloworld 180%/50% 1 10 10 92s
eap-helloworld WildFlyServer/eap-helloworld 133%/50% 1 10 10 2m2s