【问题标题】:horizontalpodautoscaler min and max replica are 1 creates 2 podsHorizo​​ntalpodautoscaler 最小和最大副本为 1 创建 2 个 pod
【发布时间】:2022-01-20 23:32:28
【问题描述】:

我正在尝试运行将混合和最大副本定义为 1 的 Horizo​​ntalpodautoscaler 资源。 不知何故,一旦它开始运行 2 个 pod 实例同时运行,则 1 个 pod 被终止。 结束状态我有 1 个 Pod 正在运行。

这是 HPA 资源的正常行为,它以某种方式创建了具有 2 个 pod 的副本集,即使最大值是 1 个

谢谢

【问题讨论】:

  • 您的集群部署在哪里?我在 GKE 中遇到了同样的问题。
  • 在常规虚拟机而非 GKE 上运行的 openshift 集群中

标签: kubernetes


【解决方案1】:

一般不会发生。如果 hpa 目标指标目标非常低并且启动应用程序超过目标 CPU 阈值导致 Pod 扩展,则可能发生这种情况的唯一原因。

您可以查看 HPA 状态,events section 可以解释缩放的原因。

HPA 状态:kubectl describe HPA_NAME

查看以下示例以供参考

    Metrics:                                               ( current / target )
  resource cpu on pods  (as a percentage of request):  40% (406m) / 50%
Min replicas:                                          10
Max replicas:                                          100
Conditions:
  Type            Status  Reason              Message
  ----            ------  ------              -------
  AbleToScale     True    ReadyForNewScale    the last scale time was sufficiently old as to warrant a new scale
  ScalingActive   True    ValidMetricFound    the HPA was able to succesfully calculate a replica count from cpu resource utilization (percentage of request)
  ScalingLimited  False   DesiredWithinRange  the desired replica count is within the acceptible range
Events:
  Type    Reason             Age                   From                       Message
  ----    ------             ----                  ----                       -------
  Normal  SuccessfulRescale  35m (x1216 over 12d)  horizontal-pod-autoscaler  New size: 10; reason: All metrics below target


【讨论】:

  • 我注意到以某种方式创建了 2 个副本集,然后创建了 2 个 Pod,但随后 HPA 验证当前状态为 2,期望为 1 并杀死其中一个 Pod。即使我没有任何 CPU 问题,这是否正常
  • 检查部署定义,如果副本设置为 2,则将其更改为 1。spec: replicas: 2
  • 创建了 1 个但仍然有 2 个 pod 和 2 个副本集,然后 1 个被 HPA 终止
  • 我分享了部署规范和状态
  • 这无济于事。你是在为 example-ms 使用部署还是复制集?
【解决方案2】:

这些是来自所有相关资源的事件流:

HPA Events:
NAME            REFERENCE                  TARGETS         MINPODS   MAXPODS   REPLICAS   AGE
example-ms   Deployment/example-ms   <unknown>/50%   1         1         0          0s
example-ms   Deployment/example-ms   <unknown>/50%   1         1         0         1s
example-ms   Deployment/example-ms   <unknown>/50%   1         1         2         3s
example-ms   Deployment/example-ms   <unknown>/50%   1         1         1         33s


Replica Set Events:
NAME                              DESIRED   CURRENT   READY     AGE
example-ms-59c9b45565   1         1         0         1s
example-ms-76896c7f7f   1         1         1         2s
example-ms-59c9b45565   1         1         1         2s
example-ms-76896c7f7f   1         1         1         32s
example-ms-59c9b45565   1         1         1         32s
example-ms-76896c7f7f   0         1         1         32s
example-ms-76896c7f7f   0         1         1         32s
example-ms-76896c7f7f   0         0         0         32s

Pod Events:
NAME                                    READY     STATUS              RESTARTS   AGE
example-ms-59c9b45565-6b5v8   0/1       ContainerCreating   0         0s
example-ms-76896c7f7f-cth7x   1/1       Running   0         2s
example-ms-59c9b45565-6b5v8   1/1       Running   0         2s
example-ms-59c9b45565-d2k8w   0/1       Terminating   0         2m
example-ms-59c9b45565-d2k8w   0/1       Terminating   0         2m
example-ms-59c9b45565-d2k8w   0/1       Terminating   0         2m
example-ms-59c9b45565-d2k8w   0/1       Terminating   0         2m
example-ms-76896c7f7f-cth7x   1/1       Terminating   0         32s
example-ms-76896c7f7f-cth7x   0/1       Terminating   0         1m
example-ms-76896c7f7f-cth7x   0/1       Terminating   0         1m
example-ms-76896c7f7f-cth7x   0/1       Terminating   0         1m




Deployment Spec:
spec:
  minReadySeconds: 30
  progressDeadlineSeconds: 120
  replicas: 1
  revisionHistoryLimit: 15
  selector:



Deployment status:
tatus:
  availableReplicas: 1
  conditions:
  - lastTransitionTime: 2019-04-21T08:51:03Z
    lastUpdateTime: 2019-04-21T08:51:35Z
    message: ReplicaSet "example-ms-59c9b45565" has successfully progressed.
    reason: NewReplicaSetAvailable
    status: "True"
    type: Progressing
  - lastTransitionTime: 2019-04-21T16:53:02Z
    lastUpdateTime: 2019-04-21T16:53:02Z
    message: Deployment has minimum availability.
    reason: MinimumReplicasAvailable
    status: "True"
    type: Available
  observedGeneration: 3
  readyReplicas: 1
  replicas: 1
  updatedReplicas: 1

【讨论】:

    【解决方案3】:

    我建议您检查是否在 deployment.yaml 中定义了“副本”。 如果您定义了它,那么 pod 的初始数量将是您在副本上设置的数量。 之后,HPA 将开始工作并杀死其中一个 pod,因为您将最大值定义为 1。 如需更多帮助,请分享您的 *.yaml 文件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-11
      • 2021-02-03
      • 1970-01-01
      • 2023-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-21
      相关资源
      最近更新 更多