<p>There is an elastic search container running on localhost on port 9200, but from a pod on the same host, I'm unable to curl the localhost port 9200</p>
<pre><code>[root@jenkins ~]# netstat -tupln | grep 9200
tcp6       0      0 :::9200                 :::*                    LISTEN      4148/docker-proxy


[jenkins@kb-s-9xttg agent]$ curl http://localhost:9200
curl: (7) Failed to connect to ::1: Network is unreachable
</code></pre>
<p>/etc/hosts</p>
<pre><code># Kubernetes-managed hosts file.
127.0.0.1       localhost
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
fe00::0 ip6-mcastprefix
fe00::1 ip6-allnodes
fe00::2 ip6-allrouters
192.168.255.23  kbs-9xttg
</code></pre>
<p>I am able to <code>curl public_host_ip:9200</code></p>
<p>elastic-search container is not managed by Kubernetes but running on the same host.</p>
<p>Why is the pod unable to talk to <code>localhost:9200</code> or <code>127.0.0.1:9200</code> ?</p>

Sanjay M. P.
<p><em>Summary from the comments:</em></p>
<p>If you're talking to localhost from within a Pod, you're only talking to the containers inside that Pod.</p>
<p>Containers in different Pods have distinct IP addresses and can not communicate by using localhost. They might however be exposing their own port on your local host network, similar to what your Docker container is doing (which is why you can communicate from your local node using localhost).</p>
<p>Inside your cluster you can use the Pod IPs, but if you want to talk to your host you need to use host networking for your Pod</p>
<pre><code>spec:
   hostNetwork: true
</code></pre>
<p>or the external IP of your host.</p>
<p>More on <a href="https://kubernetes.io/docs/concepts/cluster-administration/networking/" rel="nofollow noreferrer">Kubernetes Networking in the docs</a> and <a href="https://medium.com/google-cloud/understanding-kubernetes-networking-pods-7117dd28727" rel="nofollow noreferrer">this blog post</a>.</p>
