简体   繁体   English

Docker Kubernetes (Mac) - Autoscaler 无法找到指标

[英]Docker Kubernetes (Mac) - Autoscaler unable to find metrics

I have installed a local instance of Kubernetes via Docker on my Mac.我已经通过 Docker 在我的 Mac 上安装了 Kubernetes 的本地实例。

Following the walkthrough on how to activate autoscaling on a deployment I have experienced an issue.按照有关如何在部署上激活自动缩放的演练,我遇到了一个问题。 The autoscaler can't read the metrics.自动调节程序无法读取指标。

When I am running kubectl describe hpa the current cpu usage comes back as unknown / 50% with the warnings:当我运行kubectl describe hpa ,当前的 cpu 使用率返回为unknown / 50%并带有警告:

Warning FailedGetResourceMetric: horizontal-pod-autoscaler unable to get metrics for resource cpu: unable to fetch metrics from API: the server could not find the requested resource (get pods.metrics.k8s.io)警告 FailedGetResourceMetric:horizo​​ntal-pod-autoscaler 无法获取资源 cpu 的指标:无法从 API 获取指标:服务器找不到请求的资源(获取 pods.metrics.k8s.io)

Warning FailedComputeMetricsReplicas horizontal-pod-autoscaler failed to get cpu utilization: unable to get metrics for resource cpu: unable to fetch metrics from API: the server could not find the requested resource (get pods.metrics.k8s.io)警告 FailedComputeMetricsReplicas horizo​​ntal-pod-autoscaler 无法获取 cpu 利用率:无法获取资源 cpu 的指标:无法从 API 获取指标:服务器找不到请求的资源(获取 pods.metrics.k8s.io)

I have installed the metrics-server via git clone https://github.com/kubernetes-incubator/metrics-server.git and installed it with kubectl create -f deploy/1.8+我已经通过git clone https://github.com/kubernetes-incubator/metrics-server.git安装了度量服务器,并使用kubectl create -f deploy/1.8+安装了它

I finally got it working.. Here are the full steps I took to get things working:我终于让它工作了..以下是我为使事情工作而采取的完整步骤:

  1. Have Kubernetes running within Docker在 Docker 中运行 Kubernetes

  2. Delete any previous instance of metrics-server from your Kubernetes instance with kubectl delete -n kube-system deployments.apps metrics-server使用kubectl delete -n kube-system deployments.apps metrics-server从 Kubernetes 实例中删除任何以前的 metrics-server 实例

  3. Clone metrics-server with git clone https://github.com/kubernetes-incubator/metrics-server.git使用git clone https://github.com/kubernetes-incubator/metrics-server.git克隆度量服务器

  4. Edit the file deploy/1.8+/metrics-server-deployment.yaml to override the default command by adding a command section that didn't exist before.编辑文件deploy/1.8+/metrics-server-deployment.yaml以通过添加以前不存在的命令部分来覆盖默认命令。 The new section will instruct metrics-server to allow for an insecure communications session (don't verify the certs involved).新部分将指示 metrics-server 允许不安全的通信会话(不要验证所涉及的证书)。 Do this only for Docker, and not for production deployments of metrics-server:仅针对 Docker 执行此操作,而不针对 metrics-server 的生产部署执行此操作:

     containers: - name: metrics-server image: k8s.gcr.io/metrics-server-amd64:v0.3.1 command: - /metrics-server - --kubelet-insecure-tls
  5. Add metrics-server to your Kubernetes instance with kubectl create -f deploy/1.8+ (if errors with the .yaml, write this instead: kubectl apply -f deploy/1.8+ )使用kubectl create -f deploy/1.8+将 metrics-server 添加到您的 Kubernetes 实例(如果 .yaml 出错,请改写: kubectl apply -f deploy/1.8+

  6. Remove and add the autoscaler to your deployment again.再次删除自动缩放程序并将其添加到您的部署中。 It should now show the current cpu usage.它现在应该显示当前的 CPU 使用情况。

EDIT July 2020: 2020 年 7 月编辑:

Most of the above steps hold true except the metrics-server has changed and that file does not exist anymore.除了度量服务器已更改并且该文件不再存在之外,上述大多数步骤都适用。

The repo now recommends installing it like this:回购现在建议像这样安装它:

apply -f https://github.com/kubernetes-sigs/metrics-server/releases/download/v0.3.6/components.yaml

So we can now download this file,所以我们现在可以下载这个文件,

curl -L https://github.com/kubernetes-sigs/metrics-server/releases/download/v0.3.6/components.yaml --output components.yaml

add --kubelet-insecure-tls under args (L88) to the metrics-server deployment and runargs (L88) 下添加--kubelet-insecure-tlsmetrics-server部署并运行

kubectl apply -f components.yaml

For who are use Internal-IP here may work for you.对于在这里使用内部 IP 的人可能对你有用。 Follow @Mr.Turtle above at step 4. add more one command.在第 4 步中按照上面的 @Mr.Turtle 操作。添加更多一个命令。

  containers:
  - name: metrics-server
    image: k8s.gcr.io/metrics-server-amd64:v0.3.3
    command:
      - /metrics-server
      - --kubelet-insecure-tls
      - --kubelet-preferred-address-types=InternalIP

我们升级到 AWS EKS 版本 1.13.7,那时我们开始遇到 HPA 问题,结果在我的部署中我不得不为resources.requests.cpu=200m指定一个值,然后 HPA 开始为我工作。

Had same issue while using my kubernetes kubeadm lab and the updated procedure is here https://github.com/kubernetes-sigs/metrics-server使用我的 kubernetes kubeadm 实验室时遇到了同样的问题,更新的程序在这里https://github.com/kubernetes-sigs/metrics-server

This solved the issue: horizontal-pod-autoscaler unable to get metrics for resource cpu: unable to fetch metrics from resource metrics API: the server could not find the requested resource (get pods.metrics.k8s.io)这解决了问题:horizo​​ntal-pod-autoscaler无法获取资源cpu的指标:无法从资源指标API获取指标:服务器找不到请求的资源(获取pods.metrics.k8s.io)

If someone still has problems fixing this issue, this helped me fix it on minikube:如果有人仍然无法解决此问题,这有助于我在 minikube 上修复它:

I had 2 deployments with the same label, something like this:我有 2 个具有相同标签的部署,如下所示:

kind: Deployment
metadata:
  name: webserver
spec:
  selector:
    matchLabels:
      app: web
  template:
    metadata:
      labels:
        app: web

---

kind: Deployment
metadata:
  name: database
spec:
  selector:
    matchLabels:
      app: web
  template:
    metadata:
      labels:
        app: web

I renamed the label and matchLabels of the database (eg to app: db), then deleted both deployments and applied the new config - et voilà it worked.我重命名了数据库的标签和 matchLabels(例如到 app: db),然后删除了两个部署并应用了新的配置 - 等等,它起作用了。 (after hours of trying to solve the problem..) (经过数小时的尝试解决问题..)

Further informations to this issue: https://github.com/kubernetes/kubernetes/issues/79365此问题的更多信息: https : //github.com/kubernetes/kubernetes/issues/79365

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

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