<p>In short I have two containers in a pod, named <code>a</code> and <code>b</code>, on ports 80 and 9000 respectively. They can reach each other through <code>127.0.0.1:80</code> and <code>127.0.0.1:9000</code>. Can they also reach each other by name?</p>

<p>I've tried <code>a.podname:90</code>, <code>b.podname:9000</code>, <code>podname:80</code> and other variations without luck.</p>

<p>There is <a href="http://kubernetes.io/docs/admin/dns/#a-records" rel="nofollow noreferrer">http://kubernetes.io/docs/admin/dns/#a-records</a> but those are based on the PODs assigned IP which isn't known beforehand.</p>

<p>There is also <a href="http://kubernetes.io/docs/admin/dns/#srv-records" rel="nofollow noreferrer">http://kubernetes.io/docs/admin/dns/#srv-records</a> but they depend on the service, and thus the readiness criteria. Also SRV is a DNS extension that can sometimes not be used.</p>

<p>Background: To keep containers compatible with both Kubernetes and other docker environments you must avoid dependencies to localhost, but can depend on fixed port numbers. For example if there is a name that resolves to 127.0.0.1 or the POD's IP in Kubernetes, that same name can be used as a <a href="https://docs.docker.com/compose/compose-file/#/links" rel="nofollow noreferrer">https://docs.docker.com/compose/compose-file/#/links</a> alias in docker-compose.</p>

<p>In particular I'm trying to solve <a href="https://github.com/Reposoft/docker-svn/issues/8" rel="nofollow noreferrer">https://github.com/Reposoft/docker-svn/issues/8</a></p>

<p>If you're always going to run the two containers in a pod, you <em>can</em> rely on <code>localhost:xyz</code> to be accessible, no matter where that pod gets scheduled. </p>

<p>If you want to use DNS names, you can create <a href="http://kubernetes.io/docs/user-guide/services/#headless-services" rel="nofollow noreferrer">a headless service</a> for the SRV records. You can override the readiness behavior using an annotation: <a href="https://github.com/kubernetes/kubernetes/blob/10aee82ae3bf8ec8f8926e5198efceae1384e0b8/pkg/controller/endpoint/endpoints_controller.go#L58-L64" rel="nofollow noreferrer">service.alpha.kubernetes.io/tolerate-unready-endpoints</a>. That should give you a DNS name to reach your pod.</p>
