Kubectl顶级节点`错误:指标尚不可用`,将指标服务器用作已取消的堆栈

w8biq8rn  于 2022-09-19  发布在  Docker
关注(0)|答案(7)|浏览(126)

Kubernetes找不到度量服务器api。我正在Mac上使用Kubernetes和Docker。我试着从following example开始做HPA。然而,当我执行命令kubectl get hpa时,我的目标仍然未知。然后我试了,kubectl describe hpa。这给了我如下错误:

Name:                                                  php-apache
  Namespace:                                             default
  Labels:                                                <none>
  Annotations:                                           <none>
  CreationTimestamp:                                     Sun, 07 Oct 2018 12:36:31 -0700
  Reference:                                             Deployment/php-apache
  Metrics:                                               ( current / target )
    resource cpu on pods  (as a percentage of request):  <unknown> / 5%
  Min replicas:                                          1
  Max replicas:                                          10
  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  1h (x34 over 5h)  horizontal-pod-autoscaler  failed to get cpu utilization: unable to get metrics for resource cpu: no metrics returned from resource metrics API
    Warning  FailedGetResourceMetric       1m (x42 over 5h)  horizontal-pod-autoscaler  unable to get metrics for resource cpu: no metrics returned from resource metrics API

我按照Kubernetes文档中的建议使用metrics-server。我也试着用小库做了同样的事情。但这也没有奏效。

运行kubectl get --raw /apis/metrics.k8s.io/v1beta1/nodes输出:

{
  "kind": "NodeMetricsList",
  "apiVersion": "metrics.k8s.io/v1beta1",
  "metadata": {
    "selfLink": "/apis/metrics.k8s.io/v1beta1/nodes"
  },
  "items": []
}
xkftehaa

xkftehaa1#

使用官方指标服务器-https://github.com/kubernetes-sigs/metrics-server

如果您使用一个主节点,请运行以下命令来创建metrics-server

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

如果您有HA(高可用性)群集,请使用以下命令:

kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/high-availability.yaml

然后,用户可以使用kubectl top nodeskubectl top pods -A,得到如下内容:

NAME          CPU(cores)   CPU%   MEMORY(bytes)   MEMORY%
mnemlml8

mnemlml82#

解决方案(如果使用Minikube):

  • 将Kubernetes的上下文更改为Minikube*。

  • 启用指标-mini kube中的服务器和禁用堆栈。*

minikube addons disable heapster

minikube addons enable metrics-server

  • 在您的集群中部署指标服务器,步骤如下:*

git clone https://github.com/kubernetes-incubator/metrics-server.git

cd metrics-server

kubectl create -f deploy/1.7/(如果是Kubernetes版本1.7)

kubectl create -f deploy/1.8+/(如果Kubernetes版本1.8+)

启动minikube dashboadminikube service [your service]

试试kubectl top node

我发现这个(https://kubernetes.io/docs/tasks/configure-pod-container/assign-memory-resource/)资源很有帮助。

idfiyjo8

idfiyjo83#

在您的群集中使用以下命令设置Metrics Server:

kubectl apply -f https://raw.githubusercontent.com/pythianarora/total-practice/master/sample-kubernetes-code/metrics-server.yaml

这应该可以很好地工作。

我在metrics-server中关闭了TLS,它在之后开始工作,所以我更新了YAML并重新发布了。

vltsax25

vltsax254#

我知道这是一个迟来的答案,但我自己和Docker Kubernetes和Autoscaler有一些问题,在互联网上找不到好的答案。经过多天的调试,我发现metrics-server存在一些连接问题(无法连接到Pod)。

我关闭了metrics-server中的TLS,它开始工作。如果其他人遇到了同样的问题,我在这里回复了自己的帖子:

Docker Kubernetes (Mac) - Autoscaler unable to find metrics

xqk2d5yq

xqk2d5yq5#

确保您使用的是Kubernetes集群上的最新metrics-server。下面的命令帮助了我。

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

参考链接:https://github.com/kubernetes-sigs/metrics-server

pkwftd7m

pkwftd7m6#

问题是证书,更新您下载的YAML部署部分以安装metrics-server as,
将此部件添加到文件中:--kubelet-insecure-tls

containers:
      - name: metrics-server
        image: k8s.gcr.io/metrics-server/metrics-server:v0.3.7
        imagePullPolicy: IfNotPresent
        args:
          - --kubelet-insecure-tls

现在,完整的部署如下所示:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: metrics-server
  namespace: kube-system
  labels:
    k8s-app: metrics-server
spec:
  selector:
    matchLabels:
      k8s-app: metrics-server
  template:
    metadata:
      name: metrics-server
      labels:
        k8s-app: metrics-server
    spec:
      serviceAccountName: metrics-server
      volumes:
      # mount in tmp so we can safely use from-scratch images and/or read-only containers
      - name: tmp-dir
        emptyDir: {}
      containers:
      - name: metrics-server
        image: k8s.gcr.io/metrics-server/metrics-server:v0.3.7
        imagePullPolicy: IfNotPresent
        args:
          - --kubelet-insecure-tls
          - --cert-dir=/tmp
          - --secure-port=4443
        ports:
        - name: main-port
          containerPort: 4443
          protocol: TCP
        securityContext:
          readOnlyRootFilesystem: true
          runAsNonRoot: true
          runAsUser: 1000
        volumeMounts:
        - name: tmp-dir
          mountPath: /tmp
      nodeSelector:
        kubernetes.io/os: linux
e7arh2l6

e7arh2l67#

当使用mini kube 1.4.0时,除了minikube startkubectl top node/pod应该开箱即用之外,不需要做任何其他事情。

相关问题