如何在Kubernetes中获取Pod的资源使用情况

如何在Kubernetes中获取Pod的资源使用情况

本文介绍了如何在Kubernetes中获取Pod的资源使用情况?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过命令行获取Kubernetes上每个Pod的实际资源使用情况(而非资源请求)?Heapster已过时.同时,Metrics-server仍然不支持kubectl top pod.

How can we get the real resource usage (not resource requests) of each pod on Kubernetes by command line?Heapster is deprecated.Meanwhile, Metrics-server still does not support kubectl top pod.

  1. 堆-

  1. Heapster -

我使用以下命令部署了Heapster

I deployed Heapster using the following command

$ heapster/deploy/kube.sh start
kubectl get pods --all-namespaces
NAMESPACE     NAME                                                           READY     STATUS    RESTARTS   AGE
kube-system   calico-node-hlcbl                                              2/2       Running   0          39m
kube-system   calico-node-m8jl2                                              2/2       Running   0          35m
kube-system   coredns-78fcdf6894-bl94w                                       1/1       Running   0          39m
kube-system   coredns-78fcdf6894-fwx95                                       1/1       Running   0          39m
kube-system   etcd-ctl.kube.yarnrm-pg0.utah.cloudlab.us                      1/1       Running   0          39m
kube-system   heapster-84c9bc48c4-qzt8x                                      1/1       Running   0          15s
kube-system   kube-apiserver-ctl.kube.yarnrm-pg0.utah.cloudlab.us            1/1       Running   0          39m
kube-system   kube-controller-manager-ctl.kube.yarnrm-pg0.utah.cloudlab.us   1/1       Running   0          38m
kube-system   kube-proxy-nj9f8                                               1/1       Running   0          35m
kube-system   kube-proxy-zvr2b                                               1/1       Running   0          39m
kube-system   kube-scheduler-ctl.kube.yarnrm-pg0.utah.cloudlab.us            1/1       Running   0          39m
kube-system   monitoring-grafana-555545f477-jldmz                            1/1       Running   0          15s
kube-system   monitoring-influxdb-848b9b66f6-k2k4f                           1/1       Running   0          15s

使用kubectl top时,遇到以下错误.

When I used kubectl top, I encountered the following errors.

$ kubectl top pods
Error from server (ServiceUnavailable): the server is currently unable to handle the request (get services http:heapster:)
$ kubectl top nodes
Error from server (ServiceUnavailable): the server is currently unable to handle the request (get services http:heapster:)

  • 指标服务器:

  • metrics-server:

    metrics-server不支持kubectl top 资源指标API

    metrics-server has not supported kubectl top Resource Metrics API

    如果有人已经解决了相同的问题,请帮助我.谢谢.

    If anyone already solved the same problem, please help me.Thanks.

    推荐答案

    这听起来像是只是部署了stackster部署而忘记为heapster安装Service了;我希望这能使您克服那个错误,但不知道它是否真的会导致kubectl top pods开始工作:

    It sounds like the heapster deployment just forgot to install the Service for heapster; I would expect this would get you past that error, but unknown whether it would actually cause kubectl top pods to start to work:

    kubectl create -f /dev/stdin <<SVC
    apiVersion: v1
    kind: Service
    metadata:
      name: heapster
      namespace: kube-system
    spec:
      selector:
        whatever-label: is-on-heapster-pods
      ports:
      - name: http
        port: 80
        targetPort: whatever-is-heapster-is-listening-on
    SVC
    

    这篇关于如何在Kubernetes中获取Pod的资源使用情况?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

  • 09-01 21:12