简体   繁体   English

Kubernetes hpa 无法获取内存指标(明确说明时)

[英]Kubernetes hpa can't get memory metrics (when it is clearly stated)

I am trying to implement autoscaling of pods in my cluster.我正在尝试在我的集群中实现 pod 的自动缩放。 I have tried with a "dummy" deployment and hpa, and I didn't have problem.我尝试过“虚拟”部署和 hpa,但没有问题。 Now, I am trying to integrate it into our "real" microservices and it keeps returning现在,我正在尝试将它集成到我们的“真实”微服务中,并且它不断返回

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

Here is my hpa:这是我的 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

The deployment部署

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}

I can see both memory and cpu when I do kubectl top pods .当我执行kubectl top pods时,我可以看到内存和 CPU。 I can see the requests and limits as well when I do kubectl describe pod .当我执行kubectl describe pod时,我也可以看到请求和限制。

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

The only difference I can think of is that my dummy service didn't have linkerd sidecar.我能想到的唯一区别是我的虚拟服务没有 linkerd sidecar。

For the HPA to work with resource metrics, every container of the Pod needs to have a request for the given resource (CPU or memory).为了让 HPA 处理资源指标,Pod 的每个容器都需要对给定资源(CPU 或内存)进行请求。

It seems that the Linkerd sidecar container in your Pod does not define a memory request (it might have a CPU request). Pod 中的 Linkerd sidecar 容器似乎没有定义内存请求(它可能有 CPU 请求)。 That's why the HPA complains about missing request for memory .这就是 HPA 抱怨missing request for memory的原因。

However, you can configure the memory and CPU requests for the Linkerd container with the --proxy-cpu-request and --proxy-memory-request injection flags .但是,您可以使用--proxy-cpu-request--proxy-memory-request注入标志为 Linkerd 容器配置内存和 CPU 请求。

Another possibility is to use these annotations to configure the CPU and memory requests:另一种可能性是使用这些注解来配置 CPU 和内存请求:

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

Defining a memory request with in either of these ways should make the HPA work.以这些方式中的任何一种定义内存请求都应该使 HPA 工作。

References:参考:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM