简体   繁体   English

Kubernetes HPA -- 无法获取资源内存指标:没有从资源指标 API 返回指标

[英]Kubernetes HPA -- Unable to get metrics for resource memory: no metrics returned from resource metrics API

Good afternoon下午好

I'm just starting with Kubernetes, and I'm working with HPA (HorizontalPodAutoscaler):我刚开始使用 Kubernetes,我正在使用 HPA(Horizo​​ntalPodAutoscaler):

apiVersion: autoscaling/v2beta2
kind: HorizontalPodAutoscaler
metadata:
  name: find-complementary-account-info-1
spec:
  scaleTargetRef:
    apiVersion: apps/v1
    kind: Deployment
    name: find-complementary-account-info-1
  minReplicas: 2
  maxReplicas: 5
  metrics:
  - type: Resource
    resource:
      name: memory
      target:
        type: AverageValue
        averageUtilization: 50

But when I try to see the metrics on the console, it doesn't show me:但是当我尝试在控制台上查看指标时,它没有显示:

    [dockermd@tmp108 APP-MM-ConsultaCuentaPagadoraPospago]$ kubectl get hpa
    NAME                                REFERENCE                                      TARGETS         MINPODS   MAXPODS   REPLICAS   AGE
    find-complementary-account-info-1   Deployment/find-complementary-account-info-1   <unknown>/50%   2         5         2          143m

My manifiest is:我的清单是:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: find-complementary-account-info-1
  labels:
    app: find-complementary-account-info-1
spec:
  replicas: 2
  selector:
    matchLabels:
      app: find-complementary-account-info-1
  template:
    metadata:
      labels:
        app: find-complementary-account-info-1
    spec:
      containers:
      - name: find-complementary-account-info-1
        image: find-complementary-account-info-1:latest
        imagePullPolicy: IfNotPresent
        resources:
          limits:
            memory: "350Mi"
          requests:
            memory: "300Mi"
        ports:
        - containerPort: 8083
        env:
        - name: URL_CONNECTION_BD
          value: jdbc:oracle:thin:@10.161.6.15:1531/DEFAULTSRV.WORLD
        - name: USERNAME_CONNECTION_BD
          valueFrom:
            secretKeyRef:
              name: credentials-bd-pers
              key: user_pers
        - name: PASSWORD_CONNECTION_BD
          valueFrom:
            secretKeyRef:
              name: credentials-bd-pers
              key: password_pers
apiVersion: v1
kind: Service
metadata:
  name: svc-find-complementary-account-info-1
  labels:
    app: find-complementary-account-info-1
  namespace: default
spec:
  selector:
    app: find-complementary-account-info-1
  type: LoadBalancer
  ports:
   -
    protocol: TCP
    port: 8083
    targetPort: 8083
    nodePort: 30025
  externalIPs:
    - 10.161.174.68

Show me the tag给我看标签

Also if I perform a kubect describe hpa, it throws me the following:此外,如果我执行 kubect describe hpa,它会抛出以下内容:

[dockermd@tmp108 APP-MM-ConsultaCuentaPagadoraPospago]$ kubectl describe hpa find-complementary-account-info-1
Name:                                                     find-complementary-account-info-1
Namespace:                                                default
Labels:                                                   <none>
Annotations:                                              <none>
CreationTimestamp:                                        Thu, 29 Oct 2020 13:57:58 -0400
Reference:                                                Deployment/find-complementary-account-info-1
Metrics:                                                  ( current / target )
  resource memory on pods  (as a percentage of request):  <unknown> / 50%
Min replicas:                                             2
Max replicas:                                             5
Deployment pods:                                          2 current / 0 desired
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: unable to get metrics for resource memory: no metrics returned from resource metrics API
Events:
  Type     Reason                   Age                     From                       Message
  ----     ------                   ----                    ----                       -------
  Warning  FailedGetResourceMetric  4m49s (x551 over 144m)  horizontal-pod-autoscaler  unable to get metrics for resource memory: no metrics returned from resource metrics API

I am not working in the cloud, I am working in an on-premise environment configured with Bare-Metal我不在云中工作,我在配置了裸机的本地环境中工作

Also install metrics-server:还要安装指标服务器:

[dockermd@tmp108 APP-MM-ConsultaCuentaPagadoraPospago]$ kubectl get deployment metrics-server -n kube-system
NAME             READY   UP-TO-DATE   AVAILABLE   AGE
metrics-server   1/1     1            1           177m

What will I lack?我会缺少什么? Could someone give me a hand?有人可以帮我一把吗?

[dockermd@tmp108 certs]$ kubectl describe pod metrics-server -n kube-system
Name:         metrics-server-5f4b6b9889-6pbv8
Namespace:    kube-system
Priority:     0
Node:         tmp224/10.164.21.169
Start Time:   Thu, 29 Oct 2020 13:27:19 -0400
Labels:       k8s-app=metrics-server
              pod-template-hash=5f4b6b9889
Annotations:  cni.projectcalico.org/podIP: 10.244.119.140/32
              cni.projectcalico.org/podIPs: 10.244.119.140/32
Status:       Running
IP:           10.244.119.140
IPs:
  IP:           10.244.119.140
Controlled By:  ReplicaSet/metrics-server-5f4b6b9889
Containers:
  metrics-server:
    Container ID:  docker://f71d26dc2c8e787ae9551faad66f9588a950bf0a6d0d5cb90ff11ceb219e9b37
    Image:         k8s.gcr.io/metrics-server-amd64:v0.3.6
    Image ID:      docker-pullable://k8s.gcr.io/metrics-server-amd64@sha256:c9c4e95068b51d6b33a9dccc61875df07dc650abbf4ac1a19d58b4628f89288b
    Port:          4443/TCP
    Host Port:     0/TCP
    Args:
      --cert-dir=/tmp
      --secure-port=4443
    State:          Running
      Started:      Thu, 29 Oct 2020 13:27:51 -0400
    Ready:          True
    Restart Count:  0
    Environment:    <none>
    Mounts:
      /tmp from tmp-dir (rw)
      /var/run/secrets/kubernetes.io/serviceaccount from metrics-server-token-4mn92 (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             True
  ContainersReady   True
  PodScheduled      True
Volumes:
  tmp-dir:
    Type:       EmptyDir (a temporary directory that shares a pod's lifetime)
    Medium:
    SizeLimit:  <unset>
  metrics-server-token-4mn92:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  metrics-server-token-4mn92
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  kubernetes.io/arch=amd64
                 kubernetes.io/os=linux
Tolerations:     node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                 node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:          <none>

The error unable to get metrics for resource memory: no metrics returned from resource metrics API is not caused by faulty HPA but by metrics-server that is not able to scrape any metrics. unable to get metrics for resource memory: no metrics returned from resource metrics API的错误unable to get metrics for resource memory: no metrics returned from resource metrics API不是由故障 HPA 引起的,而是由无法抓取任何指标的指标服务器引起的。

Most of the time this error is caused by missing commands in metrics-server deployment .大多数情况下,此错误是由metrics-server deployment 中缺少命令引起的。 It can be done by adding following arguments in the deployment.可以通过在部署中添加以下参数来完成。

  --kubelet-insecure-tls
  --kubelet-preferred-address-types=InternalIP,ExternalIP

Since you are using apiVersion: autoscaling/v2beta2 , the correct way to specify scaling policy based on resources would be,由于您使用的是apiVersion: autoscaling/v2beta2 ,根据资源指定扩展策略的正确方法是,

type: Resource
resource:
  name: cpu
  target:
    type: Utilization
    averageUtilization: 60

You can also specify resource metrics in terms of direct values, instead of as percentages of the requested value, by using a target.type of AverageValue instead of Utilization, and setting the corresponding target.averageValue field instead of the target.averageUtilization您还可以通过使用 target.type 的 AverageValue 而不是 Utilization 并设置相应的target.averageValue字段而不是target.averageUtilization ,根据直接值而不是请求值的百分比来指定资源指标

And if you want to try out with v2beta1 , you can try the below piece of yml in metrics,如果你想尝试v2beta1 ,你可以尝试下面的 yml 指标,

 type: Resource
 resource:
    name: memory
    targetAverageUtilization: 60

The problem is at:问题出在:

target: type: AverageValue averageUtilization: 50目标:类型:AverageValue averageUtilization:50

You specified the type "AverageValue" but with "averageUtilization".您指定了“AverageValue”类型,但使用“averageUtilization”。 You should either change type: to "Utilization" or value field with "averageValue".您应该将 type: 更改为“Utilization”或使用“averageValue”的值字段。

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

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