<p>I am trying to connect to the MongoDB replica set that is hosted in another Kubernetes cluster of the same GCP project. I want to use <a href="https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/" rel="nofollow noreferrer">DNS names</a> in the connection string.</p>
<p>I was able to connect to mongodb hosted in the same cluster using this connection string:</p>
<pre><code>mongodb://&lt;pod-name&gt;.&lt;service-name&gt;.&lt;namespace&gt;.svc.cluster.local:27017,&lt;pod-name&gt;.&lt;service-name&gt;.&lt;namespace&gt;.svc.cluster.local:27017/?replicaSet=&lt;rs-name&gt;
</code></pre>
<p>So my question is:</p>
<p>Is it possible to use the DNS name to reference the pod in another cluster? I looked through <a href="https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/" rel="nofollow noreferrer">this document</a> and it states:</p>
<blockquote>
<p>Any pods created by a Deployment or DaemonSet have the following DNS
resolution available:</p>
<p><code>pod-ip-address.deployment-name.my-namespace.svc.cluster-domain.example.</code></p>
</blockquote>
<p>But I am not sure what is the format of the <code>cluster-domain.example</code> part.</p>

<p>You can not use Kubernetes Service DNS(CoreDNS) to access a pod from outside the kubernetes cluster even from another kubernetes cluster. You need to expose the mongodb pod via <code>LoadBalancer</code>(recommended) or <code>NodePort</code> type service and access it using <code>LoadBalancer endpoint</code> or <code>NodeIP:NodePort</code> from the other kubernetes cluster.</p>
