Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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!

like image 204
Jerry Zhang Avatar asked Nov 20 '25 15:11

Jerry Zhang


1 Answers

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
like image 101
Matt Avatar answered Nov 23 '25 05:11

Matt