Kubernetes HPA 错误地计算 CPU 的平均利用率

发布于 2025-01-09 07:18:45 字数 847 浏览 1 评论 0原文

我正在设置基于 CPU 的 nginx 自动缩放。

nginx 部署的设置是:

        resources:
          limits:
            cpu: "2"
            memory: 1000Mi
          requests:
            cpu: 100m
            memory: 100Mi

当我检查 kubectl top pod 时,

我看到我有 4 个 pod。每个 Pod 使用 2m。所以总共 8m。有人可以向我解释一下,当我检查 HPA 时,它显示 44%/50% 的利用率如何?这个数学绝对是错误的。

HPA 配置:

apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: api-svc-nginx-ingress
  namespace: api-svc
spec:
  maxReplicas: 5
  minReplicas: 1
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: nginx-ingress
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 50

如果我手动将部署缩减到 1 个 Pod,我会发现利用率下降到 8%/50%...不确定出了什么问题?公制服务器坏了吗?

I am setting up nginx autoscaling based on CPU.

Setup on the nginx deployment is:

        resources:
          limits:
            cpu: "2"
            memory: 1000Mi
          requests:
            cpu: 100m
            memory: 100Mi

When I check kubectl top pod

I see I have 4 pods. Each pod is using 2m. So that is 8m total. Can someone explain to me how when I check the HPA it shows 44%/50% is utilized? That math is definitely wrong.

HPA config:

apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: api-svc-nginx-ingress
  namespace: api-svc
spec:
  maxReplicas: 5
  minReplicas: 1
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: nginx-ingress
  metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 50

If I manually scale down the deployment to 1 pod I see that the utilization drops to 8%/50%... Not sure whats wrong? Is metric server broken?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

哀由 2025-01-16 07:18:45

所以事实证明我使用了一个不起作用的附加指标(这是一个自定义指标,没有来自指标服务器的来源) - 我认为这破坏了指标的更新。

我有另一个

  metrics:
  - type: Object

显示在 HPA 目标输出上的内容。当我删除这个指标后,HPA 似乎工作得很好。

So it turns out I was using an additional metric that wasn't working (it was a custom metric that didn't have a source from metric server) - and I think that broke the metrics from updating.

I had another

  metrics:
  - type: Object

that was showing up as on the HPA targets output. Once I removed that metric the HPA seemed to work fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文