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


使用 EAP 操作器时,您可以使用 pod 横向自动扩展 HPA 根据从属于该 EAP 应用的容器集收集的指标来自动增加或减少 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
    Copy to Clipboard Toggle word wrap
    重要

    您必须指定 pod 中的容器的资源限值和请求,以便自动扩展才能按预期工作。

  2. 创建 Horizontal pod 自动缩放器:

    oc autoscale wildflyserver/eap-helloworld --cpu-percent=50 --min=1 --max=10
    Copy to Clipboard Toggle word wrap

验证

  • 您可以通过检查副本来验证 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
Copy to Clipboard Toggle word wrap
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat