<p>I've a scenario where I want to fetch the node's IP address from inside a pod which is hosted on that same node (daemonset pod). As, I want to put a check something like - if the <strong>pod-A</strong> already exists on the same node(identify using that node's IP address) then wait for it to terminate otherwise create the <strong>pod-A</strong> again. While trying to implement the same in K8s go-client, I'm unable to find a way getting the node's IP from inside the pod on which that pod is currently scheduled. The best I've come across is this method: <a href="https://github.com/kubernetes/kubernetes/blob/v1.20.4/pkg/util/node/node.go#L149" rel="nofollow noreferrer">https://github.com/kubernetes/kubernetes/blob/v1.20.4/pkg/util/node/node.go#L149</a> but the problem being it requires to pass node name as well along with it. Is there any other way to get the same information from inside the Pod?</p>

NightOwl19
<p>The <a href="https://pkg.go.dev/golang.org/x/build/kubernetes/api#PodStatus" rel="nofollow noreferrer"><code>PodStatus</code></a> field in the <a href="https://pkg.go.dev/golang.org/x/build/kubernetes/api#Pod" rel="nofollow noreferrer"><code>Pod</code></a> structure has the <code>HostIP</code> field which you can use to get the IP of the node on which the pod is running.</p>
<p>You can see an example <a href="https://github.com/vladimirvivien/k8s-client-examples/blob/master/go/podlist/maing.go" rel="nofollow noreferrer">here</a> on how to get the list of pods in a namespace and iterating over them.</p>
