<p>I have an application pod running on a namespace named frontend and a database pod running on a different namespace named backend. I need to have communication between both the pods residing in different namespaces. The database container is up and running but while the application container has an error of crashloopbackoff. </p>

<p>When I saw the logs of the application pod, there is an error while resolving the database hostname which was provided through the environment variable PGHOST and was equal to the name of the database container. But it seems that the application container is unable to resolve the database host.</p>

<p>Therefore, how should I connect them. I suppose that the problem is due to different namespaces. So how do I connect them and make them communicate.</p>

<p>error:</p>

<pre><code>&gt; The Gemfile's dependencies are satisfied rake aborted!
&gt; PG::ConnectionBad: could not translate host name "postgres" to
&gt; address: Name or service not known
</code></pre>

<p>I am assuming you have a <a href="https://kubernetes.io/docs/concepts/services-networking/service/#publishing-services-service-types" rel="nofollow noreferrer">ClusterIP</a> type service with name <code>postgres </code> in <code>xyz</code> namespace. Then you can access it from another namespace by specifying <code>postgres.xyz</code></p>
<p>Kubernetes has a DNS system <a href="https://coredns.io" rel="nofollow noreferrer">CoreDNS</a> which will resolve the hostname <code>postgres.xyz</code> to the POD IP.</p>
