Access Kubernetes Api from a Pod with Java-Client Library

596 views Asked by At

im currently using the client java kubernetes library to get metrics from the Kubernetes API

<dependency>
    <groupId>io.kubernetes</groupId>
    <artifactId>client-java</artifactId>
    <version>12.0.0</version>
</dependency>

I found out that some Metrics regarding Network and Filesystem I/O, located under this path https://kubernetes.default.svc/api/v1/nodes/worker02/proxy/metrics/cadvisor are really interesting.

container_network_receive_bytes_total{container="",id="/kubepods/besteffort/podb6bf750b-4501-4082-9a50-3751ff1e4f0f/72f84fc52547c628baeee527a47faa204eadd660ba4cbb94d8889562ff0b7789",image="docker.io/rancher/pause:3.1",interface="eth0",name="72f84fc52547c628baeee527a47faa204eadd660ba4cbb94d8889562ff0b7789",namespace="kube-system",pod="svclb-traefik-2wlkz"} 50398 1618932055188

However as they are in prometheus metrics format there is no support for them by the library.

Getting the Information with a http client was not successful (javax.net.ssl.SSLHandshakeException) as I realized later because I am not passing Token and Certificate. Is there a way to use the client-java lib to just get the raw answer of the API?

I am thinking of something like this, thanks in advance

String apiAnswer = client.getRaw("/api/v1/nodes/worker02/proxy/metrics/cadvisor");
1

There are 1 answers

1
Rafał Leszko On

You can make a call using ApiClient directly. Something like this.

ApiClient client = Config.defaultClient();
ApiResponse<Object> result = client.execute(client.buildCall(...));