Communication between pods on different namespaces

4/14/2020

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.

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.

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.

error:

> The Gemfile's dependencies are satisfied rake aborted!
> PG::ConnectionBad: could not translate host name "postgres" to
> address: Name or service not known
-- selina
kubernetes
kubernetes-pod
minikube

1 Answer

4/14/2020

I am assuming you have a ClusterIP type service with name postgres in xyz namespace. Then you can access it from another namespace by specifying postgres.xyz

Kubernets has a DNS system CoreDNS which will resolve the hostname postgres.xyz to the POD IP.

-- Arghya Sadhu
Source: StackOverflow