pkdone / gke-mongodb-demo

Demo project showing how to deploy MongoDB on the Google Container Engine (GKE) with Kubernetes
MIT License
97 stars 39 forks source link

Missing sample connection URL in README #6

Open djensen47 opened 6 years ago

djensen47 commented 6 years ago

It might be nice to include what the connection URL would be inside the cluster for this setup.

It seems like it would be:

mongodb://mongod-0.mongodb-service,mongod-1.mongodb-service,mongod-2.mongodb-service:27017/dbname
flauc commented 6 years ago

Did you ever manage to connect? I can't seem to figure it out, this is the url I'm trying:

`mongodb://${MONGO_CONFIG.auth.user}:${MONGO_CONFIG.auth.password}@mongod-0.mongodb-service,mongod-1.mongodb-service,mongod-2.mongodb-service:27017/${DB_NAME}`
djensen47 commented 6 years ago

The url I posted works for me.

flauc commented 6 years ago

@djensen47 thanks 👍

caiobegotti commented 6 years ago

I would rather leave the primary/secondary handling for the service itself, so I am using this: mongodb://user:pass@mongodb.default.svc.cluster.local/?replicaSet=MainRepSet&authSource=admin (I also have 3 replicas)

That gives you this (I am debugging it with a Java app), note the other replica hostnames handled automatically:

org.mongodb.driver.cluster: Monitor thread successfully connected to server with description ServerDescription{address=mongodb-0.mongodb.default.svc.cluster.local:27017, type=REPLICA_SET_PRIMARY, state=CONNECTED, ok=true, ..., setName='MainRepSet', canonicalAddress=mongodb-0.mongodb.default.svc.cluster.local:27017, hosts=[mongodb-2.mongodb.default.svc.cluster.local:27017, mongodb-0.mongodb.default.svc.cluster.local:27017, mongodb-1.mongodb.default.svc.cluster.local:27017], ..., primary='mongodb-0.mongodb.default.svc.cluster.local:27017', ...}
org.mongodb.driver.cluster: Setting max election id to 7fffffff0000000000000001 from replica set primary mongodb-0.mongodb.default.svc.cluster.local:27017
org.mongodb.driver.cluster: Setting max set version to 1 from replica set primary mongodb-0.mongodb.default.svc.cluster.local:27017
org.mongodb.driver.cluster: Discovered replica set primary mongodb-0.mongodb.default.svc.cluster.local:27017