<p>I have created mongo-statefulset in kubernetes and all the 3 pods are running, </p>

<pre><code>NAME                                     READY   STATUS    RESTARTS   AGE
mongo-0                                  1/1     Running   0          40m
mongo-1                                  1/1     Running   0          40m
mongo-2                                  1/1     Running   0          40m
mysql-5456cbb767-t8g2g                   1/1     Running   0          3h45m
nfs-client-provisioner-5d77dc5bd-mcz8p   1/1     Running   0          42m

</code></pre>

<p>however after initiating and reconfigure the first member of the replica set with the correct DNS name, could not add the remaining replica sets.</p>

<pre><code>&gt;rs.initiate()
&gt;var cfg = rs.conf()
&gt;cfg.members[0].host="mongo‑0.mongo:27017"
&gt;rs.reconfig(cfg)
</code></pre>

<p>Add the second member give me this error</p>

<pre><code>rs0:PRIMARY&gt; rs.add("mongo‑1.mongo:27017")
{
    "operationTime" : Timestamp(1590453966, 1),
    "ok" : 0,
    "errmsg" : "Quorum check failed because not enough voting nodes responded; required 2 but only the following 1 voting nodes responded: mongo-0:27017; the following nodes did not respond affirmatively: mongo‑1.mongo:27017 failed with Error connecting to mongo‑1.mongo:27017 :: caused by :: Could not find address for mongo‑1.mongo:27017: SocketException: Host not found (authoritative)",
    "code" : 74,
    "codeName" : "NodeNotFound",
    "$clusterTime" : {
        "clusterTime" : Timestamp(1590453966, 1),
        "signature" : {
            "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
            "keyId" : NumberLong(0)
        }
    }
}
rs0:PRIMARY&gt;
</code></pre>

<p>Also using hostname -f on all the nodes returns the correct hostname of the nodes.
eg. </p>

<pre><code>ubuntu@k8s-master:~$ hostname -f
k8s-master
</code></pre>

<p>Any idea as how to solve this problem?</p>

<p>Services deployed</p>

<pre><code>ubuntu@k8s-master:~$ kubectl get svc --all-namespaces=true -o wide
NAMESPACE              NAME                        TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)                  AGE     SELECTOR
default                kubernetes                  ClusterIP   10.96.0.1        &lt;none&gt;        443/TCP                  20h     &lt;none&gt;
default                mongo                       ClusterIP   None             &lt;none&gt;        27017/TCP                7h59m   app=mongo
default                mysql                       ClusterIP   None             &lt;none&gt;        3306/TCP                 11h     app=mysql
default                nrf-instance-service        NodePort    10.96.18.198     &lt;none&gt;        9090:30005/TCP           10h     app=nrf-instance
kube-system            kube-dns                    ClusterIP   10.96.0.10       &lt;none&gt;        53/UDP,53/TCP,9153/TCP   20h     k8s-app=kube-dns
kube-system            metrics-server              ClusterIP   10.111.247.62    &lt;none&gt;        443/TCP                  11h     k8s-app=metrics-server
kubernetes-dashboard   dashboard-metrics-scraper   ClusterIP   10.97.205.147    &lt;none&gt;        8000/TCP                 20h     k8s-app=dashboard-metrics-scraper
kubernetes-dashboard   kubernetes-dashboard        NodePort    10.100.212.222   &lt;none&gt;        443:32648/TCP            20h     k8s-app=kubernetes-dashboard

</code></pre>

<p>Also is the dns checked on each mongo pod</p>

<pre><code>ubuntu@k8s-master:~$ kubectl exec -ti mongo-0 -- cat /etc/resolv.conf
nameserver 10.96.0.10
search default.svc.cluster.local svc.cluster.local cluster.local
options ndots:5
ubuntu@k8s-master:~$ kubectl exec -ti mongo-1 -- cat /etc/resolv.conf
nameserver 10.96.0.10
search default.svc.cluster.local svc.cluster.local cluster.local
options ndots:5
ubuntu@k8s-master:~$ kubectl exec -ti mongo-2 -- cat /etc/resolv.conf
nameserver 10.96.0.10
search default.svc.cluster.local svc.cluster.local cluster.local
options ndots:5

</code></pre>

<pre><code>ubuntu@k8s-master:~$ kubectl exec -ti mongo-0 -- nslookup kubernetes.default
Server:     10.96.0.10
Address:    10.96.0.10#53

Name:   kubernetes.default.svc.cluster.local
Address: 10.96.0.1

ubuntu@k8s-master:~$ kubectl exec -ti mongo-1 -- nslookup kubernetes.default
Server:     10.96.0.10
Address:    10.96.0.10#53

Name:   kubernetes.default.svc.cluster.local
Address: 10.96.0.1

ubuntu@k8s-master:~$ kubectl exec -ti mongo-2 -- nslookup kubernetes.default
Server:     10.96.0.10
Address:    10.96.0.10#53

Name:   kubernetes.default.svc.cluster.local
Address: 10.96.0.1


</code></pre>

<p>statefulset.yaml content</p>

<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 
        - "--bind_ip_all"
        - "--replSet"
        - rs0
        ports:
        - containerPort: 27017
        volumeMounts:
        - name: mongo-volume
          mountPath: /data/db
  volumeClaimTemplates:
  - metadata:
      name: mongo-volume
    spec:
      accessModes: [ "ReadWriteOnce" ]
      resources:
        requests:
          storage: 5Gi

</code></pre>

<p>kubectl get endpoints mongo -oyaml </p>

<pre><code>apiVersion: v1
kind: Endpoints
metadata:
  annotations:
    endpoints.kubernetes.io/last-change-trigger-time: "2020-05-26T08:27:18Z"
  creationTimestamp: "2020-05-26T00:42:16Z"
  labels:
    app: mongo
    service.kubernetes.io/headless: ""
  managedFields:
  - apiVersion: v1
    fieldsType: FieldsV1
    fieldsV1:
      f:metadata:
        f:annotations:
          .: {}
          f:endpoints.kubernetes.io/last-change-trigger-time: {}
        f:labels:
          .: {}
          f:app: {}
          f:service.kubernetes.io/headless: {}
      f:subsets: {}
    manager: kube-controller-manager
    operation: Update
    time: "2020-05-26T08:27:18Z"
  name: mongo
  namespace: default
  resourceVersion: "114014"
  selfLink: /api/v1/namespaces/default/endpoints/mongo
  uid: 0a7faaa4-9de7-4a14-b101-04fc5884d23c
subsets:
- addresses:
  - hostname: mongo-1
    ip: 10.244.1.16
    nodeName: k8s-worker-node2
    targetRef:
      kind: Pod
      name: mongo-1
      namespace: default
      resourceVersion: "114012"
      uid: 249f3cf6-aa2b-4d4e-a736-671dd1942fc7
  - hostname: mongo-2
    ip: 10.244.2.28
    nodeName: k8s-worker-node1
    targetRef:
      kind: Pod
      name: mongo-2
      namespace: default
      resourceVersion: "113775"
      uid: 796a80d9-889e-4fdd-88f2-0baf3ed080c6
  - hostname: mongo-0
    ip: 10.244.2.31
    nodeName: k8s-worker-node1
    targetRef:
      kind: Pod
      name: mongo-0
      namespace: default
      resourceVersion: "113825"
      uid: 8948c536-43fd-46c4-9132-d5afe145ede7
  ports:
  - name: mongo
    port: 27017
    protocol: TCP

</code></pre>

<p>Adding with the </p>

<pre><code>rs0:PRIMARY&gt; rs.add("mongo‑1.mongo.default.svc.cluster.local:27017")
{
    "operationTime" : Timestamp(1590526166, 1),
    "ok" : 0,
    "errmsg" : "Quorum check failed because not enough voting nodes responded; required 2 but only the following 1 voting nodes responded: mongo-0:27017; the following nodes did not respond affirmatively: mongo‑1.mongo.default.svc.cluster.local:27017 failed with Error connecting to mongo‑1.mongo.default.svc.cluster.local:27017 :: caused by :: Could not find address for mongo‑1.mongo.default.svc.cluster.local:27017: SocketException: Host not found (authoritative)",
    "code" : 74,
    "codeName" : "NodeNotFound",
    "$clusterTime" : {
        "clusterTime" : Timestamp(1590526166, 1),
        "signature" : {
            "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
            "keyId" : NumberLong(0)
        }
    }
}
rs0:PRIMARY&gt; 

</code></pre>

tom
<p>I replicated your setup and have found the issue.</p>

<p>It turned out that you were using wrong characters of hyphen.</p>

<pre><code>‑ -
</code></pre>

<p>First one (used by you) has hex representation of 0x2011. Second is a regular - with hex of 0x2d. They look almost the same but they aren't the same from dns point of view.</p>

<p>To resolve your issue you need to use a regular hyphen.
Here:</p>

<pre><code>rs.add("mongo-1.mongo:27017")
</code></pre>

<p>Try copy-pasting above command and see if it works.</p>
