7.11. 使用 pod 横向自动扩展 HPA 自动扩展 pod

通过 EAP 操作器,您可以使用 pod 横向自动扩展 HPA 根据从属于该 EAP 应用的 pod 收集的指标自动增加或减少 EAP 应用缩放。

注意

使用 HPA 可确保在 pod 缩减时仍然处理事务恢复。

流程

  1. 配置资源:

    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 中的容器指定资源限值和请求,以便自动扩展才能按预期工作。

  2. 创建 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