0

I am running 3 mongodb pods and separate service and persistent volume claims for each pod. I want to do the Mongodb replication among the 3 pods. Login into 1st pod and gave the mongo command, then i configured hosts as podname.servicename.namespace.svc.cluster.local:27017 for each pod.

rs.initiate(
  {
    "_id": "rs0",
    "members": [
      {
        "_id": 0,
        "host": "mongo-.mongo.default.svc.cluster.local:27017",
        "priority": 10
      },
      {
        "_id": 1,
        "host": "mongo-1.mongo.default.svc.cluster.local:27017",
        "priority": 9
      },
      {
        "_id": 2,
        "host": "mongo-2.mongo.default.svc.cluster.local:27017",
        "arbiterOnly": true
      }
    ]
  }
)

I am getting the error like this

replSetInitiate quorum check failed because not all proposed set members responded affirmatively: mongo-1.mongo.default.svc.cluster.local:27017 failed with Error connecting to mongo-1.mongo.default.svc.cluster.local:27017 (10.36.0.1:27017) :: caused by :: Connection refused, mongo-2.mongo.default.svc.cluster.local:27017 failed with Error connecting to mongo-2.mongo.default.svc.cluster.local:27017 (10.44.0.3:27017) :: caused by :: Connection refused

Here i have dought on whether cluster-IP or node-IP it takes as host while doing the MongoDB replication in kubernetes cluster.

Could anybody suggest me how to configure the host-name while doing the mongodb replication in kubernates?

jbarros
  • 628
  • 10
  • 28
BSG
  • 673
  • 2
  • 13
  • 33

2 Answers2

3

You must explicitly bind mongod to the non-loopback interface since mongo 3.6, according to the fine manual

You can test that theory yourself by exec-ing into mongo-1.mongo.default and attempting to manually connect to mongo-2.mongo.default, which I am about 90% certain will fail for you in the same way it fails for mongod.

mdaniel
  • 31,240
  • 5
  • 55
  • 58
  • (a) that sounds like a new question (b) you seriously want me to debug your problem without one ounce of logs? (c) [you clearly did not even attempt to answer that yourself](https://duckduckgo.com/?q=%22mongod%22+%22Couldn%27t+get+a+connection+within+the+time+limit%22&atb=v73-4_q&ia=web) – mdaniel Nov 30 '18 at 05:20
0

If you are using AWS and are trying to set up replication over multiple instances, make sure you have enabled Inbound traffic in the Security Group.

Go to the security group, click the edit inbound rules button, and then add rules.

Example: 2nd rule in the image

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 03 '22 at 18:24