Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MongoDBCommunity not using the replicaSetHorizons values to generate Mongo Uri resulting in MongoNetworkError #1614

Open
MichaelKora opened this issue Sep 5, 2024 · 4 comments

Comments

@MichaelKora
Copy link

MichaelKora commented Sep 5, 2024

What did you do to encounter the bug?
I followed this guide to deploy a MongoDBCommunity instance with external access But i am struggling to connect to the instance as described in the documentation.

Steps to reproduce the behavior:

  1. Apply the following config using kubectl:
apiVersion: mongodbcommunity.mongodb.com/v1
kind: MongoDBCommunity
metadata:
  name: my-mongo-db
  namespace: mongodb
spec:
  members: 2
  arbiters: 1
  type: ReplicaSet
  version: "4.4.13"
  replicaSetHorizons:
    - horizon: my-mongodb-0.example.com:31181
    - horizon: my-mongodb-1.example.com:31182
    - horizon: my-mongo-db-arb-0.example.com:31183

  security:
    tls:
      enabled: true
      certificateKeySecretRef:
        name: mongodb-tls
      caConfigMapRef:
        name: ca-config-map
    authentication:
      modes: ["SCRAM"]
  users:
    - name: my-db-admin
      db: admin
      passwordSecretRef:
        name: mongodb-secret
        key: mongo-root-password
      roles:
        - name: clusterAdmin
          db: admin
        - name: userAdminAnyDatabase
          db: admin
        - name: root
          db: admin
        - name: readWrite
          db: test_db
        - name: root
          db: test_db
      scramCredentialsSecretName: my-scram
  additionalMongodConfig:
    storage.wiredTiger.engineConfig.journalCompressor: zlib
  prometheus:
    username: my-prom-user
    passwordSecretRef:
      name: prom-pwd
  statefulSet:
    spec:
      dnsPolicy: None
      dnsConfig:
         nameservers:
           - xx.xx.xx.xxx
           - yy.yy.yy.yyy

My Certificate:

apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
  name: cert-manager-certificate
  namespace: mongodb
spec:
  secretName: mongodb-tls
  issuerRef:
    name: ca-issuer
    kind: Issuer
  commonName: "*.my-mongo-db-svc.mongodb.svc.cluster.local"
  dnsNames:
    - "*.my-mongo-db-svc.mongodb.svc.cluster.local"
    - my-mongo-db-0.example.com
    - my-mongo-db-1.example.com
    - my-mongo-db-arb-0.example.com

External services definitions:

---
kind: Service
apiVersion: v1
metadata:
  name: external-mongo-service-0
  namespace: mongodb
  annotations:
    kube-linter.io/ignore-all: "used for sample"
spec:
  type: NodePort
  selector:
    app: my-mongo-db-svc
    statefulset.kubernetes.io/pod-name: my-mongo-db-0
  ports:
    - protocol: TCP
      nodePort: 31181
      port: 31181
      targetPort: 27017

---
kind: Service
apiVersion: v1
metadata:
  name: external-mongo-service-1
  namespace: mongodb
  annotations:
    kube-linter.io/ignore-all: "used for sample"
spec:
  type: NodePort
  selector:
    app: my-mongo-db-svc
    statefulset.kubernetes.io/pod-name: my-mongo-db-1
  ports:
    - nodePort: 31182
      port: 31182
      targetPort: 27017

---
kind: Service
apiVersion: v1
metadata:
  name: external-mongo-arbiter-svc
  namespace: mongodb
  annotations:
    kube-linter.io/ignore-all: "used for sample"
spec:
  type: NodePort
  selector:
    app: my-mongo-db-svc
    statefulset.kubernetes.io/pod-name: my-mongo-db-arb-0
  ports:
    - nodePort: 31183
      port: 31183
      targetPort: 27017
  1. Wait until the MongoDBCommunity instance in Running state in Kubernetes and describe:
k des mdbc my-mongo-db -n mongodb
---
Name:         my-mongo-db
Namespace:    mongodb
Labels:       <none>
Annotations:  mongodb.com/v1.lastAppliedMongoDBVersion: 4.4.13
              mongodb.com/v1.lastSuccessfulConfiguration:
                {"members":2,"type":"ReplicaSet","version":"4.4.13","arbiters":1,"replicaSetHorizons":[{"horizon":"my-mongodb-0.example.com:311...
API Version:  mongodbcommunity.mongodb.com/v1
 . . . 
Status:
  Current Mongo DB Arbiters:               1
  Current Mongo DB Members:                2
  Current Stateful Set Arbiters Replicas:  1
  Current Stateful Set Replicas:           2
  Mongo Uri:                               mongodb://my-mongo-db-0.mongo-db-svc.my-mongodb.svc.cluster.local:27017,my-mongo-db-1.mongo-db-svc.my-mongodb.svc.cluster.local:27017/?replicaSet=my-mongo-db
  Phase:                                   Running
  Version:                                 4.4.13
Events:                                    <none>

What did you expect?

I expected:

  1. the FQDNs defined in the replicaSetHorizons section to be seen under the Mongo Uri when i describe the MongoDBCommunity instance in K8s, Instead of Mongo Uri: mongodb://my-mongo-db-0.mongo-db-svc.mongodb.svc.cluster.local:27017,my-mongo-db-1.mongo-db-svc.mongodb.svc.cluster.local:27017/?replicaSet=my-mongo-db .

  2. to use mongosh and the external URI to connect to the DB:

mongosh --tls --tlsCAFile mkcert/rootCA.pem --tlsCertificateKeyFile mongo-server-key.pem --username $MONGODB_USER --password $MONGODB_ROOT_PASSWORD mongodb://my-mongo-db-0.example.com:31181,my-mongo-db-1.example.com:31182 --authenticationDatabase=admin

What happened instead?
i keep getting the error

Current Mongosh Log ID: xxxxxxxxxxxxxxxxxx

Connecting to:          mongodb://<credentials>@my-mongo-db-0.example.com:31181,my-mongo-db-1.example.com:31182/?tls=true&tlsCAFile=mkcert%2FrootCA.pem&tlsCertificateKeyFile=mongo-server-key.pem&authSource=admin&appName=mongosh+2.2.10

MongoNetworkError: getaddrinfo ENOTFOUND my-mongo-db-0.my-mongo-db-svc.mongodb.svc.cluster.local

❯ k get pods -n mongodb

NAME                                           READY   STATUS    RESTARTS   AGE
my-mongo-db-0                                 2/2     Running   0          9d
my-mongo-db-1                                 2/2     Running   0          9d
my-mongo-db-arb-0                             2/2     Running   0          9d
mongodb-kubernetes-operator-5c9948c9b6-vhxrc   1/1     Running   0          9d
mongodb-kubernetes-operator-5c9948c9b6-vvptl   1/1     Running   0          9d                     

❯ kg svc -n mongodb

NAME                         TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)              AGE
external-mongo-arbiter-svc   NodePort    10.106.17.137    <none>        31183:31183/TCP      14d
external-mongo-service-0     NodePort    10.99.234.6      <none>        31181:31181/TCP      14d
external-mongo-service-1     NodePort    10.111.103.194   <none>        31182:31182/TCP      14d
my-mongo-db-svc             ClusterIP   None             <none>        27017/TCP,9216/TCP   14d

❯ k get mdbc -n mongodb

NAME           PHASE     VERSION
my-mongo-db   Running   4.4.13
@KarooolisZi
Copy link

I also have strange issue which could be related:
#1613 (comment)

@MichaelKora
Copy link
Author

any update on your issue @KarooolisZi ?

Copy link
Contributor

This issue is being marked stale because it has been open for 60 days with no activity. Please comment if this issue is still affecting you. If there is no change, this issue will be closed in 30 days.

@github-actions github-actions bot added the stale label Nov 26, 2024
@MichaelKora
Copy link
Author

MichaelKora commented Nov 26, 2024

issue still not fixed

@github-actions github-actions bot removed the stale label Nov 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants