<p>I am able to resolve pod names to ip addresses inside the corresponding containers, e.g. if I have a pod called <code>elasticsearch-0</code> and I enter the container via <code>kubectl exec -it elasticsearch-0 bash</code> I can do the following:</p>

<pre><code>curl elasticsearch-0:9200
</code></pre>

<p>and get the response:</p>

<pre><code>{
  "name" : "OUvCoFL",
  "cluster_name" : "docker-cluster",
  "cluster_uuid" : "1Vhf2-pGR0m3e4ezDRAZ0Q",
  "version" : {
    "number" : "6.1.0",
    "build_hash" : "c0c1ba0",
    "build_date" : "2017-12-12T12:32:54.550Z",
    "build_snapshot" : false,
    "lucene_version" : "7.1.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}
</code></pre>

<p>However, if I try to do this from within a different container, e.g. kibana-0, it fails with:</p>

<p><code>curl: (6) Could not resolve host: elasticsearch-0; Name or service not known</code></p>

<p>Does anyone know what I am missing?</p>

<p>Thanks</p>

João Matos
<p>A service is what you are looking for. Read <a href="https://kubernetes.io/docs/concepts/services-networking/connect-applications-service/#the-kubernetes-model-for-connecting-containers" rel="nofollow noreferrer">this</a></p>

<blockquote>
  <p>Pods can be configured to talk to the Service, and know that communication to the Service will be automatically load-balanced out to some pod that is a member of the Service.</p>
</blockquote>

<p>Create the service:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: elasticsearch
  labels:
    app: elasticsearch
spec:
  ports:
  - port: 9200
    protocol: TCP
  selector:
    app: elasticsearch
</code></pre>

<p>And <a href="https://kubernetes.io/docs/concepts/services-networking/connect-applications-service/#accessing-the-service" rel="nofollow noreferrer">access</a> the service from any pod</p>

<p><code>curl http://elasticsearch:9200</code></p>
