Search code examples
mongodbkubernetesloopbackgoogle-kubernetes-engine

How to connect Loopback API with mongdb port in Google Kubernetes Engine


I am following this blog to deploy MongoDB in GKE and I came to a point where I need to connect my Loopback-API image in different pod but the same cluster to talk to the database.

Since the local development works as aspected with this datasource.json as following:

{
  "db": {
    "host": "database",
    "port": 27017,
    "url": "",
    "database": "test",
    "password": "",
    "name": "mongoDS",
    "user": "",
    "connector": "mongodb"
  }
}

In the tutorial, it is written that, the connection string URI would be:

“mongodb://mongo-0.mongo,mongo-1.mongo,mongo-2.mongo:27017/dbname_?”

I am not sure how to implement it to the above datasource.json. Any help will be appreciated.


Solution

  • The tutorial creates a headless service with the name "mongo" in the default ns.

    Replace your "host": "database" with "host": "mongo" in your pod's datasource.json.