<p>What i intended to do:</p>

<ol>
<li>Setup Kubernetes in Digital Ocean  </li>
<li>Configure MongoDB replicaset in kubernetes</li>
</ol>

<p><strong>EDIT</strong>: Steps that i used to setup Kubernetes</p>

<p>Steps to setup master node:</p>

<p>Docker Setup using : <a href="https://kubernetes.io/docs/setup/production-environment/container-runtimes/#docker" rel="nofollow noreferrer">https://kubernetes.io/docs/setup/production-environment/container-runtimes/#docker</a></p>

<pre><code>$ sudo apt-get install -y kubelet kubeadm kubectl
$ kubeadm init —pod-network-cidr=192.168.0.0/16 —apiserver-advertise-address=&lt;MASTER_IP&gt;
$ kubectl apply -f https://docs.projectcalico.org/v3.14/manifests/calico.yaml
</code></pre>

<p>Kubernetes Version: v1.18.3
Docker Version: 19.03.8, build afacb8b7f0</p>

<p>Setting Up Nodes:</p>

<p>Docker Setup using : <a href="https://kubernetes.io/docs/setup/production-environment/container-runtimes/#docker" rel="nofollow noreferrer">https://kubernetes.io/docs/setup/production-environment/container-runtimes/#docker</a></p>

<pre><code>$ sudo apt-get install -y kubelet kubeadm kubectl
$ kubeadm join &lt;PUBLIC_IP&gt;:6443 --token &lt;token&gt; \
    --discovery-token-ca-cert-hash &lt;hash&gt;
</code></pre>

<p>I have completed step1 successfully but unable to configure repliaca set. The rs.initiate() command fails with "<strong>No host described in new configuration 1 for replica set rs0 maps to this node</strong>" error.</p>

<pre><code>$kubectl get all
NAME                                         READY   STATUS    RESTARTS   AGE
pod/mongo-0                                  1/1     Running   0          16m
pod/mongo-1                                  1/1     Running   0          16m
pod/mongo-2                                  1/1     Running   0          16m
pod/nfs-client-provisioner-5d7cbcd58-qs8r6   1/1     Running   0          43h

NAME                 TYPE        CLUSTER-IP   EXTERNAL-IP   PORT(S)     AGE
service/kubernetes   ClusterIP   10.96.0.1    &lt;none&gt;        443/TCP     2d21h
service/mongo        ClusterIP   None         &lt;none&gt;        27017/TCP   16m

NAME                                     READY   UP-TO-DATE   AVAILABLE   AGE
deployment.apps/nfs-client-provisioner   1/1     1            1           43h

NAME                                               DESIRED   CURRENT   READY   AGE
replicaset.apps/nfs-client-provisioner-5d7cbcd58   1         1         1       43h

NAME                     READY   AGE
statefulset.apps/mongo   3/3     16m
</code></pre>

<p>Below command fails:</p>

<pre><code>$kubectl exec -it mongo-0 -- mongo
MongoDB shell version v4.2.7
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&amp;gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("64863831-2775-488f-a80d-aabdeb84bad9") }
MongoDB server version: 4.2.7
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
    http://docs.mongodb.org/
Questions? Try the support group
    http://groups.google.com/group/mongodb-user
Server has startup warnings: 
2020-05-31T09:46:16.537+0000 I  CONTROL  [initandlisten] 
2020-05-31T09:46:16.537+0000 I  CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2020-05-31T09:46:16.537+0000 I  CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2020-05-31T09:46:16.537+0000 I  CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2020-05-31T09:46:16.538+0000 I  CONTROL  [initandlisten] 
---
Enable MongoDB's free cloud-based monitoring service, which will then receive and display
metrics about your deployment (disk utilization, CPU, operation statistics, etc).

The monitoring data will be available on a MongoDB website with a unique URL accessible to you
and anyone you share the URL with. MongoDB may use this information to make product
improvements and to suggest MongoDB products and deployment options to you.

To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
---

&gt; rs.initiate({_id: "rs0", version: 1, members: [
...   { _id: 0, host : "mongo-0.mongo:27017" },
...   { _id: 1, host : "mongo-1.mongo:27017" },
...   { _id: 2, host : "mongo-2.mongo:27017" }
... ]});
{
    "operationTime" : Timestamp(0, 0),
    "ok" : 0,
    "errmsg" : "No host described in new configuration 1 for replica set rs0 maps to this node",
    "code" : 93,
    "codeName" : "InvalidReplicaSetConfig",
    "$clusterTime" : {
        "clusterTime" : Timestamp(0, 0),
        "signature" : {
            "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
            "keyId" : NumberLong(0)
        }
    }
}
</code></pre>

<p>My yamls files:</p>

<p>1.Headless service:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: mongo
  labels:
    app: mongo
spec:
  ports:
  - name: mongo
    port: 27017
    targetPort: 27017
  clusterIP: None
  selector:
    app: mongo
</code></pre>

<ol start="2">
<li>mongodb replicate set</li>
</ol>

<pre><code>apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: mongo
spec:
  selector:
    matchLabels:
       app:  mongo
  serviceName: "mongo"
  replicas: 3
  template:
    metadata:
      labels:
        app: mongo
    spec:
      terminationGracePeriodSeconds: 10
      containers:
      - name: mongo
        image: mongo
        command:
        - mongod
        - "--replSet"
        - rs0
        - "--bind_ip_all"
        ports:
        - containerPort: 27017
        volumeMounts:
        - name: mongo-volume
          mountPath: /data/db
  volumeClaimTemplates:
  - metadata:
      name: mongo-volume
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 10Gi
</code></pre>

<p>The issue may be due to DNS. I did the below to fix it with no success:</p>

<ol>
<li>Ensured 27017 is open in Master and worker nodes</li>
</ol>

<pre><code>$ufw allow 27017
</code></pre>

<ol start="2">
<li>In .yaml tried to set "bind_ip" in .yaml file to 127.0.0.1 and 0.0.0.0</li>
</ol>

<p>Nothing worked.</p>

<p>How to fix this issue?</p>

RajKrishnan
<p>I would say that you have issue with DNS configuration (<code>No host described in new configuration 1 for replica set rs0 maps to this node</code>). </p>

<p>Not sure what could cause it as you didn't provide your environment specification, but you can troubleshoot it based on <a href="https://kubernetes.io/docs/tasks/administer-cluster/dns-debugging-resolution/" rel="nofollow noreferrer">this Kubernetes docs</a>.</p>

<p>Ive run your YAMLS on my <code>GKE</code> cluster (unfortunately I don't have access to <code>Digital Ocean cloud</code>) and it works without any issues (with <code>"--bind_ip_all"</code>).</p>

<pre><code>&gt; rs.initiate({_id: "rs0", version: 1, members: [
... ...   { _id: 0, host : "mongo-0.mongo:27017" },
... ...   { _id: 1, host : "mongo-1.mongo:27017" },
... ...   { _id: 2, host : "mongo-2.mongo:27017" }
... ... ]});
{
        "ok" : 1,
        "$clusterTime" : {
                "clusterTime" : Timestamp(1591791921, 1),
                "signature" : {
                        "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
                        "keyId" : NumberLong(0)
                }
        },
        "operationTime" : Timestamp(1591791921, 1)
</code></pre>

<p>In each of my pods, in <code>/etc/hosts</code> besides default entries I have:</p>

<pre><code>NAME      READY   STATUS    RESTARTS   AGE    IP          NODE                                     
mongo-0   1/1     Running   0          122m   10.52.1.6   gke-cluster-1-default-pool-6f885e04-9mdt
mongo-1   1/1     Running   0          121m   10.52.0.3   gke-cluster-1-default-pool-6f885e04-klkb
mongo-2   1/1     Running   0          120m   10.52.1.7   gke-cluster-1-default-pool-6f885e04-9mdt

mongo-0 pod
10.52.1.6       mongo-0.mongo.default.svc.cluster.local mongo-0

mongo-1 pod
10.52.0.3       mongo-1.mongo.default.svc.cluster.local mongo-1

mongo-2 pod
10.52.1.7       mongo-2.mongo.default.svc.cluster.local mongo-2
</code></pre>

<p>As per Kubernetes docs, <a href="https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/" rel="nofollow noreferrer">DNS for Services and Pods</a>, especially part regarding <a href="https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#pods" rel="nofollow noreferrer">pods</a>, inside your hostsfile you should have entry like:</p>

<pre><code>hostname.default-subdomain.my-namespace.svc.cluster-domain.example
</code></pre>

<p>As fast check, you can add this DNS entry manually to your <code>/etc/host</code> file in pods and verify.</p>

<p>Another workaround is <a href="https://kubernetes.io/docs/concepts/services-networking/add-entries-to-pod-etc-hosts-with-host-aliases/" rel="nofollow noreferrer">Host Aliases</a>.</p>

<p>Let me know it this help. 
If not please provide content of <code>/etc/hosts</code>and <code>/etc/resolv.conf</code> files from your pods and Kubernetes version. </p>

<p>Also Verify if there are any issues with pods <code>kubectl get pods -A</code>.</p>
