有人可以解释一下 Kubernetes HPA 的行为吗?

3

这是在 EKS K8s v1.15 上发生的事情。您可以在描述输出中看到 api 版本。millicpu 在 80 到 120 之间浮动...... 这根本不符合 HPA 输出的副本计数......

以下是 YAML:

apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
  name: sequencer
  namespace: djin-content
spec:
  minReplicas: 1
  maxReplicas: 10
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: sequencer
  metrics:
  - type: Pods
    pods:
      metricName: cpu_usage
      targetAverageValue: 500

这里是kubectl describe的内容:

[root@ip-10-150-53-173 ~]# kubectl describe hpa -n djin-content
Name:                   sequencer
Namespace:              djin-content
Labels:                 <none>
Annotations:            kubectl.kubernetes.io/last-applied-configuration:
                          {"apiVersion":"autoscaling/v2beta1","kind":"HorizontalPodAutoscaler","metadata":{"annotations":{},"name":"sequencer","namespace":"djin-con...
CreationTimestamp:      Wed, 05 Aug 2020 20:40:37 +0000
Reference:              Deployment/sequencer
Metrics:                ( current / target )
  "cpu_usage" on pods:  122m / 500
Min replicas:           1
Max replicas:           10
Deployment pods:        7 current / 7 desired
Conditions:
  Type            Status  Reason              Message
  ----            ------  ------              -------
  AbleToScale     True    SucceededRescale    the HPA controller was able to update the target scale to 4
  ScalingActive   True    ValidMetricFound    the HPA was able to successfully calculate a replica count from pods metric cpu_usage
  ScalingLimited  False   DesiredWithinRange  the desired count is within the acceptable range
Events:
  Type    Reason             Age                  From                       Message
  ----    ------             ----                 ----                       -------
  Normal  SuccessfulRescale  34m                  horizontal-pod-autoscaler  New size: 10; reason: pods metric cpu_usage above target
  Normal  SuccessfulRescale  15m (x2 over 34m)    horizontal-pod-autoscaler  New size: 6; reason: pods metric cpu_usage above target
  Normal  SuccessfulRescale  10m                  horizontal-pod-autoscaler  New size: 5; reason: All metrics below target
  Normal  SuccessfulRescale  9m51s (x2 over 23m)  horizontal-pod-autoscaler  New size: 3; reason: All metrics below target
  Normal  SuccessfulRescale  5m (x2 over 16m)     horizontal-pod-autoscaler  New size: 4; reason: pods metric cpu_usage above target
  Normal  SuccessfulRescale  4m45s (x2 over 15m)  horizontal-pod-autoscaler  New size: 5; reason: pods metric cpu_usage above target
  Normal  SuccessfulRescale  4m30s                horizontal-pod-autoscaler  New size: 7; reason: pods metric cpu_usage above target

自定义指标API的填充频率和运行良好。部署目标完美运行...我已经浏览了该API和副本计算的整个k8s代码库,这毫无意义...


指定 targetAverageValue: 500m 而不是 targetAverageValue: 500 有影响吗? - Brian Pursley
不,Kubernetes 的本机单位是毫。每当您提到某些内容而没有单位时,默认为1/1000。因此,当定义为500m时,行为是相同的。 - Scott
2个回答

1
似乎度量标准不匹配,你有122m(百万分之一核心)与/ 500的原始某些东西。
  "cpu_usage" on pods:  122m / 500

您没有说明计算自定义指标的方式,可能是在122m中多加了一个0,使其成为1220 / 500(我假设cpu_usage是自定义指标,因为常规指标服务器指标只是cpu),但您可以尝试:
targetAverageValue: 500m

在处理器使用率方面,更常见的方法是使用指标服务器中的CPU利用率百分比进行HPA。

apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: php-apache
  namespace: default
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: php-apache
  minReplicas: 1
  maxReplicas: 10
  targetCPUUtilizationPercentage: 50
...

缩放活动由您的K8s控制平面中的kube-controlller-manager管理,如果启用了EKS控制平面日志记录,您还可以在那里查找更多信息。✌️

评论不适合进行长时间的讨论;这个对话已经被转移到聊天室了。 - Samuel Liew

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接