水平Pod自动缩放器无法在Minikube部署中获取指标

问题描述

这是一个解决的问题:https://github.com/kubernetes/minikube/issues/9370

复制步骤:

  1. $ minikube start — extra-config=controller-manager.horizontal-pod-autoscaler-upscale-delay=1m — extra-config=controller-manager.horizontal-pod-autoscaler-downscale-delay=1m — extra-config=controller-manager.horizontal-pod-autoscaler-sync-period=10s — extra-config=controller-manager.horizontal-pod-autoscaler-downscale-stabilization=1m
  2. $ minikube add-ons enable metrics-server
  3. 使用资源请求和限制创建.yaml
apiVersion: apps/v1
kind: Deployment
Metadata:
  labels:
    app: orion
  name: orion
spec:
  replicas: 1
  selector:
    matchLabels:
      app: orion
  template:
    Metadata:
      labels:
        app: orion
    spec:
      containers:
      - args:
        - -dbhost
        - mongo-db
        - -logLevel
        - DEBUG
        - -noCache
        name: fiware-orion
        image: fiware/orion:2.3.0
        imagePullPolicy: IfNotPresent
        ports:
        - containerPort: 1026
        resources:
          limits:
            cpu: 500m
            memory: 1Gi
          requests:
            cpu: 200m
            memory: 0.5Gi
      restartPolicy: Always
  1. $ kubectl -n test-1 autoscale deployment orion --min=1 --max=5 --cpu-percent=50

失败命令的完整输出

命令$ kubectl -n test-1 describe hpa orion返回:

Name:                                                  orion
Namespace:                                             udp-test-1
Labels:                                                <none>
Annotations:                                           CreationTimestamp:  Thu,01 Oct 2020 14:00:46 +0000
Reference:                                             Deployment/orion
Metrics:                                               ( current / target )
  resource cpu on pods  (as a percentage of request):  0% (0) / 20%
Min replicas:                                          1
Max replicas:                                          5
Deployment pods:                                       1 current / 1 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 cpu: no metrics returned from resource metrics API
  ScalingLimited  False   DesiredWithinRange       the desired count is within the acceptable range
Events:
  Type     Reason                        Age                   From                       Message
  ----     ------                        ----                  ----                       -------
  Warning  FailedComputeMetricsReplicas  39s (x12 over 4m27s)  horizontal-pod-autoscaler  invalid metrics (1 invalid out of 1),first error is: Failed to get cpu utilization: unable to get metrics for resource cpu: no metrics returned from resource metrics API
  Warning  FailedGetResourceMetric       24s (x13 over 4m27s)  horizontal-pod-autoscaler  unable to get metrics for resource cpu: no metrics returned from resource metrics API

命令$ minikube addons list返回:

|-----------------------------|----------|--------------|
|         ADDON NAME          | PROFILE  |    STATUS    |
|-----------------------------|----------|--------------|
| ambassador                  | minikube | disabled     |
| dashboard                   | minikube | enabled ✅   |
| default-storageclass        | minikube | enabled ✅   |
| efk                         | minikube | disabled     |
| freshpod                    | minikube | disabled     |
| gvisor                      | minikube | disabled     |
| helm-tiller                 | minikube | disabled     |
| ingress                     | minikube | enabled ✅   |
| ingress-dns                 | minikube | disabled     |
| istio                       | minikube | disabled     |
| istio-provisioner           | minikube | disabled     |
| kubevirt                    | minikube | disabled     |
| logviewer                   | minikube | disabled     |
| Metallb                     | minikube | disabled     |
| metrics-server              | minikube | enabled ✅   |
| nvidia-driver-installer     | minikube | disabled     |
| nvidia-gpu-device-plugin    | minikube | disabled     |
| olm                         | minikube | disabled     |
| pod-security-policy         | minikube | disabled     |
| registry                    | minikube | disabled     |
| registry-aliases            | minikube | disabled     |
| registry-creds              | minikube | disabled     |
| storage-provisioner         | minikube | enabled ✅   |
| storage-provisioner-gluster | minikube | disabled     |
|-----------------------------|----------|--------------|

您可能会在命令输出中看到,即使指标服务器似乎正常运行(hpa Orion中的指标说:resource cpu on pods (as a percentage of request): 0%),当涉及到Orion hpa产生的事件时,有关指标计算的错误

horizontal-pod-autoscaler  unable to get metrics for resource cpu: no metrics returned from resource metrics API

此水平吊舱自动缩放器无法正常工作的原因是什么?


其他详细信息:

Minikube版本:

minikube version: v1.12.1
commit: 5664228288552de9f3a446ea4f51c6f29bbdd0e0-dirty

Kubernetes版本:

$ kubeadm version

kubeadm version: &version.Info{Major:"1",Minor:"18",GitVersion:"v1.18.6",GitCommit:"dff82dc0de47299ab66c83c626e08b245ab19037",GitTreeState:"clean",BuildDate:"2020-07-15T16:56:34Z",GoVersion:"go1.13.9",Compiler:"gc",Platform:"linux/amd64"}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)