<p>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 <strong>podname.servicename.namespace.svc.cluster.local:27017</strong> for each pod.</p>

<pre><code>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
      }
    ]
  }
)
</code></pre>

<p>I am getting the error like this</p>

<blockquote>
  <p>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</p>
</blockquote>

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

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

BSG
<p>You must explicitly bind <code>mongod</code> to the non-loopback interface since mongo 3.6, according to <a href="https://docs.mongodb.com/manual/reference/configuration-options/#net.bindIp" rel="nofollow noreferrer">the fine manual</a></p>

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