2

I have installed Heapster in my Kubernetes cluster.I can give resource usage from command line, for example kubectl top pods, and Kubernetes web panel.

I'm trying to get resource usage via web API from Heapster. Actually I'd like to get resource usage (e.g: ram and cpu) a node, pod or namespace from Web API.

There is a web api http://localhost:8001/swagger-2.0.0.json in Kubernetes but there isn't any API for resource usage or Heapster data.

Is there any way to get resource usage via web API in Kubernetes ?

thanks

Meysam Mahmoodi
  • 433
  • 5
  • 19
  • Hi, [Metrics-server](https://github.com/kubernetes-incubator/metrics-server) is the successor of heapster. the following link provides the insight [monitoring_architecture](https://github.com/kubernetes/community/blob/master/contributors/design-proposals/instrumentation/monitoring_architecture.md) – Suresh Vishnoi Mar 07 '18 at 12:35
  • @SureshVishnoi could you explain more detail? – Meysam Mahmoodi Mar 07 '18 at 12:41
  • Metric-server collect all of the information from kubelet( node metics , pod metrics , etc) through Kube-Api Server. Api-server expose a endpoint so that scheduler, HPA, and kubectl can access the metics. These components do their jobs with this data. for example `kubectl top pods` show the result from that exposed api from api-server. – Suresh Vishnoi Mar 07 '18 at 12:49
  • @SureshVishnoi thanks for your explain. So I have installed `metrics-server` . how to get data via API from it? – Meysam Mahmoodi Mar 07 '18 at 12:56
  • @SureshVishnoi After installed `metrics-server`, there aren't any endpoint name `metrics.k8s.io/v1beta1` in Kubernetes API. – Meysam Mahmoodi Mar 07 '18 at 12:58
  • the api endpoint is at `/apis/metrics.k8s.io/`. [reference](https://kubernetes.io/docs/tasks/debug-application-cluster/core-metrics-pipeline/) – Suresh Vishnoi Mar 07 '18 at 13:14
  • `kubectl get --raw "/apis/metrics.k8s.io/v1beta1/nodes"` will get you the node metrics. let me know if it help you – Suresh Vishnoi Mar 07 '18 at 13:20
  • @SureshVishnoi thank you so much Suresh. I had a silly mistake in endpoint name. please send your comment as an answer and I will accept it. – Meysam Mahmoodi Mar 07 '18 at 13:46
  • Hi, so you are accessing the metrics from the metric-server ? yea I will post the answer soon. thanks – Suresh Vishnoi Mar 07 '18 at 14:07
  • @SureshVishnoi Yes I do. thanks agian – Meysam Mahmoodi Mar 07 '18 at 14:13
  • Could you please accept the answer. Therefore, we can close the question. Thanks – Suresh Vishnoi Mar 08 '18 at 09:36

1 Answers1

3

Question has been answered in the above comment section.

In order to access the Node as well as Pod Metrics, It's better to use Metrics_server which is the successor of heapster.

The metrics server collects CPU and memory usage for nodes and pods by pooling data from Kubelet.

View nodes and pods metrics:

kubectl get --raw "/apis/metrics.k8s.io/v1beta1/nodes"

kubectl get --raw "/apis/metrics.k8s.io/v1beta1/pods"

Suresh Vishnoi
  • 17,341
  • 8
  • 47
  • 55
  • Are there endpoints only for nodes and pods? Isn't there an endpoint to get data from namespaces? – Meysam Mahmoodi Mar 10 '18 at 05:59
  • When I ran`kubectl get --raw "/apis/metrics.k8s.io/v1beta1/namespaces"`, I gave `Error from server (NotFound): the server could not find the requested resource`. do you know what is that endpoint? – Meysam Mahmoodi Mar 10 '18 at 12:26
  • 1
    Node and Pod(containers) are concrete things which means they are running therefore, we can collect the metrics such as CPU and RAM. Namespace is an abstract concept. We need to find the Schema of Api server in order to understand the metrics of namespaces. for instance, Under a namespace what is the status of metrics of pods. you know what i mean – Suresh Vishnoi Mar 10 '18 at 13:27