【问题标题】:Kubernetes autoscaling not working - showing unkownKubernetes 自动缩放不起作用 - 显示未知
【发布时间】:2019-08-26 05:05:36
【问题描述】:

关于这个话题有很多问题,我尝试了很多东西,但仍然没有用。

我是 Kubernetes 新手。我有一个 Kubernetes 集群,有 2 个节点(1 台 PC,另一台 PC 上的 1 个 VM)、1 个主节点、1 个节点。我启动了一个网站(Docker Image),并且 Pod 在节点(不是主节点)上运行。现在我想自动缩放 Pod,这就是我所做的:

  1. 将--request='cpu=50m' 设置为吊舱
  2. 已创建 hpa:kubectl autoscale deployment testwebsite --min=1 --max=4 --cpu-percent=25
  3. 使用:kubectl get hpa -w

现在存在输出显示为当前值的问题。 我读了很多我必须将请求分配给 pod,就像我一样。检查通过:kubectl get pod testwebsite --out=yaml

我还创建了度量服务器版本 1.8+。确保它通过以下方式运行:kubectl get pods --all-namespaces

之后我尝试调试 HPA 并通过以下方式对其进行了查看:

kubectl describe hpa testwebsite

这向我展示了这一点:

Name:                                                  testwebsite
Namespace:                                             default
Labels:                                                <none>
Annotations:                                           <none>
CreationTimestamp:                                     Thu, 04 Apr 2019 14:08:57 +0200
Reference:                                             Deployment/testwebsite
Metrics:                                               ( current / target )   resource cpu on pods  (as a percentage of request):  <unknown> / 25%
Min replicas:                                          1
Max replicas:                                          4
Deployment pods:                                       1 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 cpu: no metrics returned from resource metrics API
Events:
  Type     Reason                        Age                   From                       Message
  ----     ------                        ----                  ----                       -------
  Warning  FailedComputeMetricsReplicas  7m24s (x12 over 10m)  horizontal-pod-autoscaler  failed to get cpu utilization: unable to get metrics for resource cpu: no metrics returned from resource metrics API
  Warning  FailedGetResourceMetric       5s (x41 over 10m)     horizontal-pod-autoscaler  unable to get metrics for resource cpu: no metrics returned from resource metrics API

10 多分钟后,它不显示当前值,即使 cpu 使用率为 50-100%,它也不会放大。

正如我所说,我是 Kubernetes 新手,我真的希望有人可以帮助我。

最好的问候,

Nico 又名 Myridor

编辑: 在两个节点上使用 Ubuntu 18.04 LTS | Kubernetes 版本:1.14.0

【问题讨论】:

    标签: kubernetes metrics autoscaling kubernetes-hpa


    【解决方案1】:

    问题不在于 HPS 本身,而在于无法抓取指标的指标服务器。

    我通过克隆 metrics-server git 然后通过 kubectl create -f deploy/1.8+/ 创建它来重新创建问题。

    接下来我编辑了指标服务器部署,运行:kubectl edit deployment metrics-server -n kube-system

    在spec: -> containers: 下添加以下标志:

    spec:
          containers:
          - command:
            - /metrics-server
            - --kubelet-insecure-tls
    

    如git中所述:

    --kubelet-insecure-tls:跳过验证 Kubelet CA 证书。不推荐用于生产,但在测试集群中很有用 带有自签名的 Kubelet 服务证书。

    更新部署并且指标服务器抓取指标后,您应该会看到 HPA 已更新为当前目标。默认抓取间隔为 60s,您可以通过在上面的--metric-resolution=10s 中添加以下标志来更改它

    【讨论】:

      【解决方案2】:

      您确定 kubernetes 指标服务器和指标 api 正在运行吗?这是首先需要的,它用于检查 CPU 使用情况和限制

      您可以从部署中删除限制(如果有)并尝试一下。

      【讨论】:

      • 如果我使用 kubectl get pods --all-namespaces 它表示指标服务器正在运行 1/1
      猜你喜欢
      • 2020-07-21
      • 1970-01-01
      • 1970-01-01
      • 2014-10-15
      • 1970-01-01
      • 2018-12-13
      • 2021-01-26
      • 1970-01-01
      • 2020-11-25
      相关资源
      最近更新 更多