How to get kubenetes cluster's metrics such as Memory CPU and so on using JAVA client

2/7/2020

I am using official java client of Kubernetes to request resources of the cluster such as Pods, Deployment and so on.

But unfortunately I found that it seems there is no API to request cluster metrics such as total CPU and Memory used by all pods.

Do you know how to get the cluster metrics using Java client ?

Thanks!

-- Jerry Zhang
java
kubernetes
metrics

2 Answers

2/9/2020

Deploy the metrics-server to the cluster.

You will then have access to query the metrics.k8s.io/v1beta1 API for pods and nodes as normal kubernetes resource. You should be able to run kubectl top pod to test.

I don't see any reason why the official java client wouldn't be able to discover these resources, but if it did they are available at the following URL's

https://api-server/apis/metrics.k8s.io/v1beta1/pods
https://api-server/apis/metrics.k8s.io/v1beta1/nodes
-- Matt
Source: StackOverflow

2/7/2020

Think you won't be able to this with official java client.

Instead of this you can set up prometheus, configure it to scrape metrics and use Prometheus HTTP API to get API response in JSON format.

-- VKR
Source: StackOverflow