【问题标题】:Kubernetes hpa can't get memory metrics (when it is clearly stated)Kubernetes hpa 无法获取内存指标(明确说明时)
【发布时间】:2019-11-27 11:53:07
【问题描述】:

我正在尝试在集群中实现 Pod 的自动缩放。我尝试过使用“虚拟”部署和 hpa,但没有问题。现在,我正在尝试将它集成到我们的“真实”微服务中,并且它会不断返回

Conditions:
  Type           Status  Reason                   Message
  ----           ------  ------                   -------
  AbleToScale    True    SucceededGetScale        the HPA controller was able to get the target's current scale
  ScalingActive  False   FailedGetResourceMetric  the HPA was unable to compute the replica count: missing request for memory
Events:
  Type     Reason                        Age                   From                       Message
  ----     ------                        ----                  ----                       -------
  Warning  FailedGetResourceMetric       18m (x5 over 19m)     horizontal-pod-autoscaler  unable to get metrics for resource memory: no metrics returned from resource metrics API
  Warning  FailedComputeMetricsReplicas  18m (x5 over 19m)     horizontal-pod-autoscaler  failed to get memory utilization: unable to get metrics for resource memory: no metrics returned from resource metrics API
  Warning  FailedComputeMetricsReplicas  16m (x7 over 18m)     horizontal-pod-autoscaler  failed to get memory utilization: missing request for memory
  Warning  FailedGetResourceMetric       4m38s (x56 over 18m)  horizontal-pod-autoscaler  missing request for memory

这是我的 hpa:


apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
 name: #{Name}
 namespace: #{Namespace}
spec:
 scaleTargetRef:
   apiVersion: apps/v1beta1
   kind: Deployment
   name: #{Name}
 minReplicas: 2
 maxReplicas: 5
 metrics:
  - type: Resource
    resource:
      name: cpu
      target:
        type: Utilization
        averageUtilization: 80
  - type: Resource
    resource:
      name: memory
      target:
        type: Utilization
        averageUtilization: 80

部署

apiVersion: apps/v1
kind: Deployment
metadata:
  name: #{Name}
  namespace: #{Namespace}
spec:
  replicas: 2
  selector:
    matchLabels:
      app: #{Name}
  template:
    metadata:
      annotations:
        linkerd.io/inject: enabled
      labels:
        app: #{Name}
    spec:
      containers:
      - name: #{Name}
        image: #{image}
        resources:
          limits:
            cpu: 500m
            memory: "300Mi"
          requests:
            cpu: 100m
            memory: "200Mi"
        ports:
        - containerPort: 80
          name: #{ContainerPort}

当我执行kubectl top pods 时,我可以看到内存和 CPU。当我执行kubectl describe pod 时,我也可以看到请求和限制。

    Limits:
      cpu:     500m
      memory:  300Mi
    Requests:
      cpu:     100m
      memory:  200Mi

我能想到的唯一区别是我的虚拟服务没有 linkerd sidecar。

【问题讨论】:

  • 公制服务器部署了吗?
  • 是的,虚拟服务也在同一个集群中。

标签: kubernetes


【解决方案1】:

为了让 HPA 使用资源指标,Pod 的每个容器都需要对给定资源(CPU 或内存)提出请求。

您的 Pod 中的 Linkerd sidecar 容器似乎没有定义内存请求(它可能有 CPU 请求)。这就是 HPA 抱怨 missing request for memory 的原因。

但是,您可以使用 --proxy-cpu-request--proxy-memory-request injection flags 配置 Linkerd 容器的内存和 CPU 请求。

另一种可能是使用these annotations来配置CPU和内存请求:

  • config.linkerd.io/proxy-cpu-request
  • config.linkerd.io/proxy-memory-request

用这两种方式中的任何一种定义内存请求都应该使 HPA 工作。

参考资料:

【讨论】:

  • 您好!你完全正确。我发现它在发布后几个小时就被链接了,还没有时间更新。我们使用这些配置 (linkerd.io/2/reference/proxy-configuration) 更新了部署,它现在可以工作了。感谢您抽出宝贵时间回答!
  • @shrimpy 您能否更新您的部署清单以反映您为纠正它所做的工作?谢谢。
  • @shrimpy,nvm。我猜他们现在用我正在使用的最新 Kubernetes v1.20 修复了它。
猜你喜欢
  • 1970-01-01
  • 2021-02-12
  • 1970-01-01
  • 2019-08-09
  • 2016-10-04
  • 2021-07-12
  • 2020-07-03
  • 2023-04-10
  • 1970-01-01
相关资源
最近更新 更多