I have three instances for kubernetes cluster and three instances for mongo cluster as shown here:
I can access my mongo cluster from app console and other compute instances using uri like this:
mongo mongodb:root:passwd@mongodb-1-servers-vm-0:27017,mongodb-1-servers-vm-1:27017/devdb?replicaSet=rs0
I also tried replacing instance names with internal and external ip addresses, but that didn't help it either.
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?
Ok, I managed to find a solution, not sure if the best one.
First we add firewall rules to allow mongodb traffic
gcloud compute firewall-rules create allow-mongodb --allow tcp:27017
Then we use external ip's to connect to mongodb from kubernetes instances
mongodb:root:passwd@<ip1>:27017,<ip2>:27017/devdb?replicaSet=rs0