'deploy mongodb with helm - why does it connect only the primary pod to replica set?

using the following command:

helm install mongodb bitnami/mongodb --set mongodbRootPassword=root --set mongodbUsername=myapp --set mongodbPassword=myapp --set mongodbDatabase=mydb --set replicaSet.enabled=true --set auth.enabled=false --set architecture=replicaset

Creating the following pods:

pod/mongodb-0           1/1     Running             0          17s
pod/mongodb-1           0/1     ContainerCreating   0          6s
pod/mongodb-arbiter-0 

But it only add the pod/mongodb-0 to the rs. when I exec into pod/mongodb-1 and do rs.status() I get

MongoServerError: no replset config has been received

What am I doing wrong?



Solution 1:[1]

The problem seems with helm install is that just giving the number of replica number is not enough and the replicaSet configuration is not done automatically. To fix this I had to run the rs.add commands manually by adding them to the values.yml file in the initdbScripts part.

So adding this to the initdbScripts in the values.yml file that I am passing in for the helm install solved the issue for me.

initdbScripts: 
  setup_replicaset_script.js : |
    rs.add("mongo-mongodb-0.mongo-mongodb-headless.svc.cluster.local:27017")
    rs.add("mongo-mongodb-1.mongo-mongodb-headless.svc.cluster.local:27017")
    rs.add("mongo-mongodb-2.mongo-mongodb-headless.svc.cluster.local:27017")

You can get the node addresses, after the helm install, in the bit that say; MongoDB® can be accessed on the following DNS name(s) and ports from within your cluster:

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 GoaKoala