<p>From the kubernetes <a href="http://kubernetes.io/docs/user-guide/pods/" rel="noreferrer">docs</a>: </p>

<blockquote>
  <p>The applications in a pod all use the same network namespace (same IP and port space), and can thus “<em>find</em>” each other and communicate using localhost.</p>
</blockquote>

<p><em>Is it possible to use some container specific names instead of <code>locahost</code>?</em> </p>

<p>For example, with <code>docker-compose up</code>, you use <em>name of the service</em> to communicate. <a href="https://docs.docker.com/compose/networking/" rel="noreferrer">[docs]</a></p>

<p>So, if my <strong>docker-compose.yml</strong> file is</p>

<pre><code>version: '2'
services:
  web:
    build: .
    ports:
      - "8000:8000"
  srv:
    build: .
    ports:
      - "3000:3000"
</code></pre>

<p>Then I access <code>srv</code> from within <code>web</code> by calling <code>http://srv:3000/</code>, <strong>not</strong> <code>http://localhost:3000</code></p>

<p>How can I achieve the same behaviour in kubernetes? Any way to specify what name to use in pods' yaml configuration?</p>

<p><code>localhost</code> is just a name for the network loopback device (usually <code>127.0.0.1</code> for IPv4 and <code>::1</code> for IPv6). This is usually specified in your <code>/etc/hosts</code> file.</p>

<p>A pod has its own IP, so each container inside shares that IP. If these containers should be independent (i.e. don't need to be collocated), they should each be in their own pod. Then, you can define a <a href="http://kubernetes.io/docs/user-guide/services/#defining-a-service" rel="noreferrer">service</a> for each that allows DNS lookups as either "$SERVICENAME" from pods in the same namespace, or "$SERVICENAME.$NAMESPACE" from pods in different namespaces.</p>
