Get the node IP of a particular Kubernetes service through Java

9/24/2018

I have a scenario where I have a Kubernetes cluster of three nodes. Now there is a service(say testService) running on the cluster(any one of the three nodes). I would like to know if there is any way through which I can get the IP of the node on which the service is running by using the kubernetes API.

I looked through the documentation and all I could find was APIs to get the status/names of the services.

Edit: There is a UI page which targets the service. The problem is that on a new deployment the service can be scheduled on either of the three nodes.

-- Swapnil Pandey
java
kubernetes

1 Answer

9/24/2018

You should be able to do it with the Kubernetes Java API.

You can basically get it with a describe service call and picking up the endpoints of your service. An example endpoint output would look like something this:

192.168.1.1:8888,192.168.2.2:8888
-- Rico
Source: StackOverflow