<p>I have three instances for kubernetes cluster and three instances for mongo cluster as shown here:</p>

<p><a href="https://i.stack.imgur.com/uOfTE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uOfTE.png" alt="enter image description here"></a></p>

<p>I can access my mongo cluster from app console and other compute instances  using uri like this:</p>

<pre><code>mongo mongodb:root:passwd@mongodb-1-servers-vm-0:27017,mongodb-1-servers-vm-1:27017/devdb?replicaSet=rs0
</code></pre>

<p>I also tried replacing instance names with internal and external ip addresses, but that didn't help it either. </p>

<p>But the same command does not work from instances inside the kubernetes cluster. I assume that I have to configure some kind of permissions for my cubernetes cluster to access compute instances? Can someone help?</p>

Ben
<p>Ok, I managed to find a solution, not sure if the best one. </p>

<p>First we add firewall rules to allow mongodb traffic </p>

<pre><code>gcloud compute firewall-rules create allow-mongodb --allow tcp:27017
</code></pre>

<p>Then we use external ip's to connect to mongodb from kubernetes instances</p>

<pre><code>mongodb:root:passwd@&lt;ip1&gt;:27017,&lt;ip2&gt;:27017/devdb?replicaSet=rs0
</code></pre>
