<p>I have deployed a 3 pod mongodb statefulset in kubernetes and I am attempting to use the new <code>mongodb+srv</code> connection string (mongodb 3.6) to connect to the headless k8s service that has the SRV records for the cluster members.</p>

<p>However, the connection is failing as follows (the mongo command is being executed on the first pod in the satefulset):</p>

<pre><code>root@mongodb-0:/# mongo "mongodb+srv://mongodb-headless.mongo.svc.cluster.local"
FailedToParse: Hostname mongodb-0.mongodb-headless.mongo.svc.cluster.local. is not within the domain mongo.svc.cluster.local
try 'mongo --help' for more information
</code></pre>

<p>Here is the headless service configuration:</p>

<pre><code>kubectl describe svc/mongodb-headless -n mongo
Name:              mongodb-headless
Namespace:         mongo
Labels:            app=mongodb-headless
                   chart=mongodb-1.0.1
                   heritage=Tiller
                   release=mongo
Annotations:       service.alpha.kubernetes.io/tolerate-unready-endpoints=true
Selector:          app=mongodb,release=mongo
Type:              ClusterIP
IP:                None
Port:              mongodb  27017/TCP
TargetPort:        27017/TCP
Endpoints:         
192.168.16.8:27017,192.168.208.3:27017,192.168.64.9:27017
Session Affinity:  None
Events:            &lt;none&gt;
</code></pre>

<p>The mongodb cluster is functional and I can connect to the members over localhost or using a separate (non-headless) service (e.g. <code>mongo "mongodb://mongodb.mongo.svc.cluster.local"</code>).</p>

<p>Am I missing something in the <code>mongodb+srv</code> requirements/implementation or do I need to adjust something in my k8s deployment?</p>

BostonHiker
<p>The connections of <code>mongodb+srv://</code> <a href="http://docs.mongodb.com/manual/reference/connection-string/#urioption.tls" rel="nofollow noreferrer">use SSL/TLS by default</a>. You need to disable them manually by adding <code>tls=false</code> or <code>ssl=false</code>.</p>

<p>The following connection URI works for me on a MongoDB 4.2 three members replica set on GKE.</p>

<pre><code>mongo "mongodb+srv://svc-headless.my-namespace.cluster.local/?tls=false&amp;ssl=false"
</code></pre>

<p>Add <code>replicaSet</code> query option may help to connect to the right replica set.</p>

<pre><code>mongo "mongodb+srv://svc-headless.my-namespace.cluster.local/?tls=false&amp;ssl=false&amp;replicaSet=rs0"
</code></pre>
