<p><strong>Is it a request for help ?</strong> <br>
Yes</p>

<p><strong>what I am trying to do?</strong> <br>
I am trying to use stable/mongodb as <em>sub chart</em> in my main chart with replica set enabled</p>

<p><strong>steps performed</strong> <br>  </p>

<ul>
<li>added mongodb as a sub chart in chart folder</li>
<li>mention dependency of this chart in requirements.yaml</li>
</ul>

<pre><code>dependencies:
- name: mongodb
  version: "5.17.0"
  repository: "file://charts/mongodb"
</code></pre>

<ul>
<li>override sub chart values in main chart</li>
</ul>

<pre><code>mongodb:
 usePassword: true
 existingSecret: skeleton
  mongodbUsername: skeleton
  mongodbDatabase: skeleton
  replicaSet:
    ## Whether to create a MongoDB replica set for high availability or not
    enabled: true
    useHostnames: true
    name: rs0
    replicas:
      secondary: 1
      arbiter: 1
</code></pre>

<p><strong>- define secret for this</strong>
in secret for skeleton</p>

<pre><code>apiVersion: v1
kind: Secret
metadata:
  name: skeleton
type: Opaque
data:
  # mongo ha---
  mongodb-root-password: &lt;64-bit-encoded-root-password&gt; 
  mongodb-replica-set-key: &lt;64-bit-encoded-Key&gt; 
  mongodb-password: &lt;64-bit-encoded-password&gt;
</code></pre>

<p><strong>- in deployment.yaml provided headless service url  mongodb url to connect to this</strong></p>

<p>from application hosted inside same k8s cluster</p>

<p><code>mongodb://&lt;mongodbUsername-value-define-in-value.yaml&gt;:&lt;mongodb-password-value-present-in-secret&gt;@skeleton-mongodb-headless:27017/skeleton?authSource=admin&amp;replicaSet=rs0
</code></p>

<ul>
<li><strong>error i am getting</strong>
when using headless service</li>
</ul>

<pre><code>[1;30m2019-05-07 05:06:16,085[0;39m =&gt; [34mINFO [0;39m [[32mmain[0;39m] [33mcom.mongodb.diagnostics.logging.SLF4JLogger[0;39m: Cluster created with settings {hosts=[skeleton-mongodb-headless:27017], mode=MULTIPLE, requiredClusterType=REPLICA_SET, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500, requiredReplicaSetName='rs0'}
[1;30m2019-05-07 05:06:16,085[0;39m =&gt; [34mINFO [0;39m [[32mmain[0;39m] [33mcom.mongodb.diagnostics.logging.SLF4JLogger[0;39m: Adding discovered server skeleton-mongodb-headless:27017 to client view of cluster
[1;30m2019-05-07 05:06:16,175[0;39m =&gt; [34mINFO [0;39m [[32mmain[0;39m] [33mcom.mongodb.diagnostics.logging.SLF4JLogger[0;39m: No server chosen by com.mongodb.Mongo$4@359ff4d9 from cluster description ClusterDescription{type=REPLICA_SET, connectionMode=MULTIPLE, serverDescriptions=[ServerDescription{address=skeleton-mongodb-headless:27017, type=UNKNOWN, state=CONNECTING}]}. Waiting for 30000 ms before timing out
[1;30m2019-05-07 05:06:16,182[0;39m =&gt; [34mINFO [0;39m [[32mcluster-ClusterId{value='5cd11248b2cfc400017b5805', description='null'}-skeleton-mongodb-headless:27017[0;39m] [33mcom.mongodb.diagnostics.logging.SLF4JLogger[0;39m: Exception in monitor thread while connecting to server skeleton-mongodb-headless:27017
com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=null, userName='skeleton', source='admin', password=&lt;hidden&gt;, mechanismProperties={}}
    at com.mongodb.connection.SaslAuthenticator.wrapException(SaslAuthenticator.java:162)
    at com.mongodb.connection.SaslAuthenticator.access$200(SaslAuthenticator.java:39)
    at com.mongodb.connection.SaslAuthenticator$1.run(SaslAuthenticator.java:68)
    at com.mongodb.connection.SaslAuthenticator$1.run(SaslAuthenticator.java:46)
    at com.mongodb.connection.SaslAuthenticator.doAsSubject(SaslAuthenticator.java:168)
    at com.mongodb.connection.SaslAuthenticator.authenticate(SaslAuthenticator.java:46)

</code></pre>

<p><strong>queries</strong></p>

<ul>
<li>am i missing something for connection </li>
<li>Do we need to provide key in connection url for internal    communication ?</li>
</ul>

Ganesh Pol
<p>I am able to resolve this issue for authentication after deleting pv and Azure Disk.
I also used <em>release-name-mongodb</em> instead of <em>release-name-mongodb-headless</em></p>
