On a GCP project, I have a K8s architecture including 2 clusters.
I have tested my mongodb cluster from inside and ensured that its works as intended. What I'm trying to do now is to connect from a pod on another cluster. I'have exposed the mongo service using a node port on the mongodb cluster:
apiVersion: v1
kind: Service
metadata:
labels:
name: mongo
name: mongodb-service
annotations:
cloud.google.com/load-balancer-type: "Internal"
spec:
externalTrafficPolicy: Local
ports:
- name: port-mongodb
port: 27017
protocol: TCP
targetPort: 27017
selector:
role: mongo
sessionAffinity: None
type: NodePort
With the IP of my mongodb cluster:
- cluster:
certificate-authority-data: DATA+OMITTED
server: https://35.240.47.130
name: gke_myproject_europe-west1-b_mongodb
And the port of my NodePort:
mongodb-service NodePort 10.3.248.249 <none> 27017:32752/TCP 6m
From a new pod with python into the microservice cluster (exactly the same I used to test the mongodb cluster from inside), I execute the following python script:
from pymongo import MongoClient
client = MongoClient("mongodb://login:pass@35.240.47.130:32752")
database = client["testdb"]
collection = database["testcollection"]
inserted_id =
collection.insert_one({"moonlight":"sonata"}).inserted_id
The result is always an error:
pymongo.errors.ServerSelectionTimeoutError: mongo:32752: timed out
What am I doing wrong ?
UPDATE
Additionally, here is some nslookup tests from the microservices cluster. First, I check the mongodb NodePort service IP
root@pybbox-55bdc76ddb-nw5gm:/# nslookup 10.3.248.249
Server: 10.35.240.10
Address: 10.35.240.10#53
** server can't find 249.248.3.10.in-addr.arpa: NXDOMAIN
Also, I check if the cluster see the other using the cluster IP.
root@pybbox-55bdc76ddb-nw5gm:/# nslookup 35.240.47.130
Server: 10.35.240.10
Address: 10.35.240.10#53
Non-authoritative answer:
130.47.240.35.in-addr.arpa name = 130.47.240.35.bc.googleusercontent.com.
Authoritative answers can be found from: