stable/mongodb helm chart authentication issue with replicaset set true

5/7/2019

Is it a request for help ?
Yes

what I am trying to do?
I am trying to use stable/mongodb as sub chart in my main chart with replica set enabled

steps performed

  • added mongodb as a sub chart in chart folder
  • mention dependency of this chart in requirements.yaml
dependencies:
- name: mongodb
  version: "5.17.0"
  repository: "file://charts/mongodb"
  • override sub chart values in main chart
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

- define secret for this in secret for skeleton

apiVersion: v1
kind: Secret
metadata:
  name: skeleton
type: Opaque
data:
  # mongo ha---
  mongodb-root-password: <64-bit-encoded-root-password> 
  mongodb-replica-set-key: <64-bit-encoded-Key> 
  mongodb-password: <64-bit-encoded-password>

- in deployment.yaml provided headless service url mongodb url to connect to this

from application hosted inside same k8s cluster

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

  • error i am getting when using headless service
[1;30m2019-05-07 05:06:16,085[0;39m => [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 => [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 => [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 => [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=<hidden>, 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)

queries

  • am i missing something for connection
  • Do we need to provide key in connection url for internal communication ?
-- Ganesh Pol
azure-kubernetes
kubernetes
kubernetes-helm
mongodb

1 Answer

5/7/2019

I am able to resolve this issue for authentication after deleting pv and Azure Disk. I also used release-name-mongodb instead of release-name-mongodb-headless

-- Ganesh Pol
Source: StackOverflow