Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the resource usage of a pod in Kubernetes?

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. 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
    

    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:)
    
  2. metrics-server:

    metrics-server has not supported kubectl top Resource Metrics API

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

like image 327
Tan Le Avatar asked Aug 01 '18 19:08

Tan Le


People also ask

How do I check disk usage in Kubernetes?

a. You can navigate to the Azure portal, look for the Kubernetes cluster that is affected. b. In the left panel clicks on Node pools and navigate to the node pool which is reporting high disk utilization.

How can I see the logs of a pod?

Checking the logs of a running pod All that you need to do to do that is to run the following command: kubectl logs nginx-7d8b49557c-c2lx9.


1 Answers

Error from server (ServiceUnavailable): the server is currently unable to handle the request (get services http:heapster:)

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
like image 60
mdaniel Avatar answered Sep 28 '22 08:09

mdaniel