Is there a Java API to retrieve the CPU and Memory usage of the pod? I am not looking for a complete monitoring solution like using Grafana or Prometheus or not using the kubectl top pod, but wanted to retrieve the current usage using Java API. Any example or reference documentation on how to do will be of great help.
Client libraries
https://kubernetes.io/docs/reference/using-api/client-libraries/
Examples - https://github.com/kubernetes-client/java#installation
Similar questions:
how to get max usage of mem and cpu usage of pod on kubernetes
kubernetes Pod CPU usage in % from metric server
Thanks.
You can install the Metrics Server and then fetch the resource usage of Pods with direct HTTP requests to the Resource Metrics API through the API server:
GET /apis/metrics/v1alpha1/namespaces/{namespace}/pods/{pod}
The Resource Metrics API does not seem to be included in the official Java client library. So, you probably have to make the API requests manually.