Fetch system IP:PORT on which our pod is running

Asking for help? Comment out what you need so we can get more information to help you!
We have a setup where a single pod is running inside a node in our machine.

In normal Java application when we use the java.net.InetAddress.getLocalHost().getHostAddress(), it would give the system hostAddress where the server is running. But if the same API is called in a java application running inside a Kubernetes pod it would give the hostAddress of pod. Please let me know how to get the hostAddress of the system where the kubernetes pod is running and not the pod hostAddress?

Cluster information:

Kubernetes version:
Cloud being used: (put bare-metal if not on a public cloud)
Installation method:
Host OS:
CNI and version:
CRI and version:

You can format your yaml by highlighting it and pressing Ctrl-Shift-C, it will make your output easier to read.

I have no experience with Java, but container technology main goal is to isolate the application. For the application running inside a container, the “host” is the container, so it makes sense to return the pod’s IP.

From the output of the kubectl describe pod <pod-id> you can see how the hostIP field maps to the pod`s IP (see Using kubectl describe pod to fetch details about pods).

The output of kubectl get pods --output=wide shows the node in which each pod is running, and then you may get the node’s ip… I am sorry but I can’t provide any tips about how to do it in Java.

Thanks Xavi, but as mentioned looking for Java Code solution.