bitnami / charts

Bitnami Helm Charts
https://bitnami.com
Other
8.97k stars 9.2k forks source link

Mongodb-sharded does not start #7829

Closed moule3053 closed 2 years ago

moule3053 commented 3 years ago

Which chart: bitnami/mongodb-sharded

Describe the bug After running the helm chart on Kubernetes, I get the error

cannot resolve host "mongodb-mongodb-sharded-configsvr-0.mongodb-mongodb-sharded-headless.mongodb.svc.cluster.local"

from the mongos pod

To Reproduce Steps to reproduce the behavior:

  1. Run
    helm install MongoDB --set image.debug=true,mongodbRootPassword=secretpassword,replicaSetKey=seplicasetkey bitnami/mongodb-sharded --namespace mongodb
  2. See the logs of the mongos pod
  3. See error
    mongodb 14:39:23.21 
    mongodb 14:39:23.21 Welcome to the Bitnami mongodb-sharded container
    mongodb 14:39:23.22 Subscribe to project updates by watching https://github.com/bitnami/bitnami-docker-mongodb-sharded
    mongodb 14:39:23.24 Submit issues and feature requests at https://github.com/bitnami/bitnami-docker-mongodb-sharded/issues
    mongodb 14:39:23.24 
    mongodb 14:39:23.25 INFO  ==> ** Starting MongoDB Sharded setup **
    mongodb 14:39:23.33 INFO  ==> Validating settings in MONGODB_* env vars...
    mongodb 14:39:23.36 INFO  ==> Initializing Mongos...
    mongodb 14:39:23.36 INFO  ==> Writing keyfile for replica set authentication...
    mongodb 14:39:23.37 DEBUG ==> /mongos.conf mounted. Skipping keyfile location configuration
    mongodb 14:39:23.37 DEBUG ==> /mongos.conf mounted. Skipping setting port and IPv6 settings
    mongodb 14:39:23.38 DEBUG ==> /mongos.conf mounted. Skipping setting log settings
    mongodb 14:39:23.39 DEBUG ==> /mongos.conf mounted. Skipping setting config server host
    mongodb 14:39:23.40 DEBUG ==> Waiting for primary node...
    mongodb 14:39:23.40 DEBUG ==> Waiting for primary node...
    mongodb 14:39:23.40 INFO  ==> Trying to connect to MongoDB server mongodb-mongodb-sharded-configsvr-0.mongodb-mongodb-sharded-headless.mongodb.svc.cluster.local...
    cannot resolve host "mongodb-mongodb-sharded-configsvr-0.mongodb-mongodb-sharded-headless.mongodb.svc.cluster.local": lookup mongodb-mongodb-sharded-configsvr-0.mongodb-mongodb-sharded-headless.mongodb.svc.cluster.local: no such host

Expected behavior Start without error.

Helm and Kubernetes version

version.BuildInfo{Version:"v3.5.2", GitCommit:"167aac70832d3a384f65f9745335e9fb40169dc2", GitTreeState:"dirty", GoVersion:"go1.15.7"}
Client Version: version.Info{Major:"1", Minor:"19", GitVersion:"v1.19.8", GitCommit:"fd5d41537aee486160ad9b5356a9d82363273721", GitTreeState:"clean", BuildDate:"2021-02-17T12:41:51Z", GoVersion:"go1.15.8", Compiler:"gc", Platform:"linux/amd64"}
Server Version: version.Info{Major:"1", Minor:"20", GitVersion:"v1.20.7", GitCommit:"132a687512d7fb058d0f5890f07d4121b3f0a2e2", GitTreeState:"clean", BuildDate:"2021-05-12T12:32:49Z", GoVersion:"go1.15.12", Compiler:"gc", Platform:"linux/amd64"}
carrodher commented 3 years ago

Please note you can't use MongoDB as the release name since it is not a valid string (due to the uppercases):

$ helm install MongoDB --set image.debug=true,mongodbRootPassword=secretpassword,replicaSetKey=seplicasetkey bitnami/mongodb-sharded --namespace mongodb --create-namespace

Error: INSTALLATION FAILED: create: failed to create: Secret "sh.helm.release.v1.MongoDB.v1" is invalid: metadata.name: Invalid value: "sh.helm.release.v1.MongoDB.v1": a DNS-1123 subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*')

Converting it to lowercase everything works fine:

$ helm install mongodb --set image.debug=true,mongodbRootPassword=secretpassword,replicaSetKey=seplicasetkey bitnami/mongodb-sharded --namespace mongodb --create-namespace

NAME: mongodb
LAST DEPLOYED: Sun Oct 17 05:49:34 2021
NAMESPACE: mongodb
STATUS: deployed
REVISION: 1
TEST SUITE: None
NOTES:
** Please be patient while the chart is being deployed **

The MongoDB® Sharded cluster can be accessed via the Mongos instances in port 27017 on the following DNS name from within your cluster:

    mongodb-mongodb-sharded.mongodb.svc.cluster.local

To get the root password run:

    export MONGODB_ROOT_PASSWORD=$(kubectl get secret --namespace mongodb mongodb-mongodb-sharded -o jsonpath="{.data.mongodb-root-password}" | base64 --decode)

To connect to your database run the following command:

    kubectl run --namespace mongodb mongodb-mongodb-sharded-client --rm --tty -i --restart='Never' --image docker.io/bitnami/mongodb-sharded:4.4.10-debian-10-r0 --command -- mongo admin --host mongodb-mongodb-sharded

To connect to your database from outside the cluster execute the following commands:

    kubectl port-forward --namespace mongodb svc/mongodb-mongodb-sharded 27017:27017 &
    mongo --host 127.0.0.1 --authenticationDatabase admin -p $MONGODB_ROOT_PASSWORD

$ helm ls -n mongodb
NAME    NAMESPACE   REVISION    UPDATED                                 STATUS      CHART                   APP VERSION
mongodb mongodb     1           2021-10-17 05:49:34.617708656 +0000 UTC deployed    mongodb-sharded-3.9.10  4.4.10

$ kubectl get pods -n mongodb
NAME                                              READY   STATUS    RESTARTS   AGE
mongodb-mongodb-sharded-configsvr-0               1/1     Running   0          2m29s
mongodb-mongodb-sharded-mongos-68bbbd44d6-dv6cj   1/1     Running   0          2m29s
mongodb-mongodb-sharded-shard0-data-0             1/1     Running   0          2m29s
mongodb-mongodb-sharded-shard1-data-0             1/1     Running   0          2m29s

$ kubectl logs mongodb-mongodb-sharded-mongos-68bbbd44d6-dv6cj -n mongodb
mongodb 05:49:57.30 Welcome to the Bitnami mongodb-sharded container
mongodb 05:49:57.30 Subscribe to project updates by watching https://github.com/bitnami/bitnami-docker-mongodb-sharded
mongodb 05:49:57.30 Submit issues and feature requests at https://github.com/bitnami/bitnami-docker-mongodb-sharded/issues
mongodb 05:49:57.31 INFO  ==> ** Starting MongoDB Sharded setup **
mongodb 05:49:57.37 INFO  ==> Validating settings in MONGODB_* env vars...
mongodb 05:49:57.62 INFO  ==> Initializing Mongos...
mongodb 05:49:57.62 INFO  ==> Writing keyfile for replica set authentication...
mongodb 05:49:57.73 DEBUG ==> Waiting for primary node...
mongodb 05:49:57.73 DEBUG ==> Waiting for primary node...
mongodb 05:49:57.74 INFO  ==> Trying to connect to MongoDB server mongodb-mongodb-sharded-configsvr-0.mongodb-mongodb-sharded-headless.mongodb.svc.cluster.local...
cannot resolve host "mongodb-mongodb-sharded-configsvr-0.mongodb-mongodb-sharded-headless.mongodb.svc.cluster.local": lookup mongodb-mongodb-sharded-configsvr-0.mongodb-mongodb-sharded-headless.mongodb.svc.cluster.local: no such host
...
cannot resolve host "mongodb-mongodb-sharded-configsvr-0.mongodb-mongodb-sharded-headless.mongodb.svc.cluster.local": lookup mongodb-mongodb-sharded-configsvr-0.mongodb-mongodb-sharded-headless.mongodb.svc.cluster.local: no such host
mongodb 05:51:08.44 INFO  ==> Found MongoDB server listening at mongodb-mongodb-sharded-configsvr-0.mongodb-mongodb-sharded-headless.mongodb.svc.cluster.local:27017 !
mongodb 05:51:08.85 INFO  ==> MongoDB server listening and working at mongodb-mongodb-sharded-configsvr-0.mongodb-mongodb-sharded-headless.mongodb.svc.cluster.local:27017 !
mongodb 05:51:08.85 DEBUG ==> Waiting for primary host mongodb-mongodb-sharded-configsvr-0.mongodb-mongodb-sharded-headless.mongodb.svc.cluster.local to be ready...
mongodb 05:51:08.86 DEBUG ==> Validating mongodb-mongodb-sharded-configsvr-0.mongodb-mongodb-sharded-headless.mongodb.svc.cluster.local as primary node...
mongodb 05:51:09.03 INFO  ==> Primary node ready.
mongodb 05:51:09.05 INFO  ==> ** MongoDB Sharded setup finished! **

mongodb 05:51:09.11 INFO  ==> ** Starting MongoDB **
{"t":{"$date":"2021-10-17T05:51:09.145Z"},"s":"W",  "c":"SHARDING", "id":24132,   "ctx":"main","msg":"Running a sharded cluster with fewer than 3 config servers should only be done for testing purposes and is not recommended for production."}

In the above example I used the same command but using lowercases in the release name and everything is working without any issue.

The

cannot resolve host "mongodb-mongodb-sharded-configsvr-0.mongodb-mongodb-sharded-headless.mongodb.svc.cluster.local": lookup mongodb-mongodb-sharded-configsvr-0.mongodb-mongodb-sharded-headless.mongodb.svc.cluster.local: no such host

error appeared in the mongos pod while it is trying to connect to other pods, but it is something normal. The container is trying to connect to another container that is being created, once created the connection succeeds and the deployment continues without any issues.

If in your case the deployment doesn't continue after a while, please check if you installed it previously with the same name or namespace but a different password (or without a password, where a random one is autogenerated). If that is the case, there can be a discrepancy between the password from the previous deployment and this one. In that case, please try removing the PV/PVCs and deploying it from scratch (using a different namespace if possible)

github-actions[bot] commented 2 years ago

This Issue has been automatically marked as "stale" because it has not had recent activity (for 15 days). It will be closed if no further activity occurs. Thanks for the feedback.

github-actions[bot] commented 2 years ago

Due to the lack of activity in the last 5 days since it was marked as "stale", we proceed to close this Issue. Do not hesitate to reopen it later if necessary.