<p>I have deployed MongoDB ReplicaSet on Kubernetes using Helm and the chart <code>stable/mongodb-replicaset</code></p>

<p>On Kubernetes, I can connect to MongoDB using the connection string which is something of the sort</p>

<pre><code>mongodb://mongodb0.example.com:27017,mongodb1.example.com:27017,mongodb2.example.com:27017/?replicaSet=myRepl
</code></pre>

<p>In the event I change the number of replicas, the connection string would change as well, which also means that every application connecting to the database would need to be updated.</p>

<p>Is there a workaround to this?</p>

<p>I thought of creating a Service, so that only this would need to be changed, however the connection string does not pass regex validation.</p>

<p>Any help on this is appreciated.</p>

GZZ
<p>The Helm chart <code>stable/mongodb-replicaset</code> deploys also 2 headless services:</p>

<ol>
<li><code>&lt;release name&gt;-mongodb-replicaset</code></li>
<li><code>&lt;release name&gt;-mongodb-replicaset-client</code></li>
</ol>

<p>The DNS record of <code>&lt;release name&gt;-mongodb-replicaset</code> returns the address of all the replicas, so, in order to connect to the replicaset, the connection string is</p>

<p><code>"mongodb+srv://&lt;release name&gt;-mongodb-replicaset.namespace.svc.cluster.local/?tls=false&amp;ssl=false"</code></p>

<p>Note that tls and ssl have been set to false for testing as they were enabled by default.</p>
