Unable to connect to mongodb replicaset externally using NodePort and multiple end points.
sireeshau472 opened this issue · comments
What did you do to encounter the bug?
Steps to reproduce the behavior:
- Install mongodb community operator on a Kubernetes (I’m using microk8s)
helm repo add mongodb https://mongodb.github.io/helm-charts
helm install community-operator mongodb/community-operator
- Deploy MongoDB community operator ReplicaSet with NodePorts
apiVersion: mongodbcommunity.mongodb.com/v1
kind: MongoDBCommunity
metadata:
name: mongodb
spec:
members: 3
type: ReplicaSet
version: "4.2.6"
security:
authentication:
modes: ["SCRAM"]
users:
- name: adminuser
db: admin
passwordSecretRef: # a reference to the secret that will be used to generate the user's password
name: mongodb-adminuser-password
roles:
- name: readWrite
db: dev-db
- name: dbAdmin
db: dev-db
- name: readWrite
db: admin
- name: dbAdmin
db: admin
- name: clusterAdmin
db: admin
- name: userAdminAnyDatabase
db: admin
scramCredentialsSecretName: my-scram
additionalMongodConfig:
storage.wiredTiger.engineConfig.journalCompressor: zlib
# the user credentials will be generated from this secret
# once the credentials are generated, this secret is no longer required
---
apiVersion: v1
kind: Secret
metadata:
name: mongodb-adminuser-password
type: Opaque
stringData:
password: m127AKWoRG
---
apiVersion: v1
kind: Service
metadata:
labels:
app: mongodb-svc
statefulset.kubernetes.io/pod-name: mongodb-0
name: mongodb-0
namespace: default
spec:
ports:
- nodePort: 30001
port: 27017
protocol: TCP
targetPort: 27017
selector:
app: mongodb-svc
statefulset.kubernetes.io/pod-name: mongodb-0
type: NodePort
---
apiVersion: v1
kind: Service
metadata:
labels:
app: mongodb-svc
statefulset.kubernetes.io/pod-name: mongodb-1
name: mongodb-1
namespace: default
spec:
ports:
- nodePort: 30002
port: 27017
protocol: TCP
targetPort: 27017
selector:
app: mongodb-svc
statefulset.kubernetes.io/pod-name: mongodb-1
type: NodePort
---
apiVersion: v1
kind: Service
metadata:
labels:
app: mongodb-svc
statefulset.kubernetes.io/pod-name: mongodb-2
name: mongodb-2
namespace: default
spec:
ports:
- nodePort: 30003
port: 27017
protocol: TCP
targetPort: 27017
selector:
app: mongodb-svc
statefulset.kubernetes.io/pod-name: mongodb-2
type: NodePort
- Connect from inside the Kubernetes cluster. Connectivity works
kubectl run mongo-client — image=mongo
kubectl exec -it mongo-client — bash
mongosh mongodb://mongodb-0.mongodb-svc.default.svc.cluster.local:27017,mongodb-1.mongodb-svc.default.svc.cluster.local:27017,mongodb-2.mongodb-svc.default.svc.cluster.local:27017/admin?replicaSet=mongodb -u adminuser -p m127AKWoRG
mongodb [primary] dev-db> show dbs
- From an external vm, Connect using the Private IP and NodePorts of the VMs where kubernetes(microk8s) is running
mongosh mongodb://10.1.0.4:30001,10.1.0.4:30002,10.1.0.4:30003/admin?replicaSet=mongodb -u adminuser -p m127AKWoRG
ERROR
root@58bc44f91339:/# mongosh mongodb://adminuser:m127AKWoRG@10.1.0.4:30001,10.1.0.4:30002/admin?replicaSet=mongodb
Current Mongosh Log ID:64351b2539115d02752939b2
Connecting to:mongodb://<credentials>@10.1.0.4:30001,10.1.0.4:30002/admin?replicaSet=mongodb&appName=mongosh+1.8.0
MongoNetworkError: getaddrinfo ENOTFOUND mongodb-0.mongodb-svc.mytests.svc.cluster.local
- When we use directConnection= true with a single end point it works.
root@58bc44f91339:/# mongosh "mongodb://adminuser:m127AKWoRG@10.1.0.4:30001/admin?replicaSet=mongodb&directConnection=true"
Current Mongosh Log ID:643529346ee13600c54714f1
Connecting to:mongodb://<credentials>@10.1.0.4:30001/admin?replicaSet=mongodb&directConnection=true&appName=mongosh+1.8.0
Using MongoDB:4.2.6
Using Mongosh:1.8.0
For mongosh info see: https://docs.mongodb.com/mongodb-shell/
------
The server generated these startup warnings when booting
2023-04-11T05:55:13.961+0000:
2023-04-11T05:55:13.961+0000: ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2023-04-11T05:55:13.961+0000: ** See http://dochub.mongodb.org/core/prodnotes-filesystem
2023-04-11T05:55:15.230+0000:
2023-04-11T05:55:15.230+0000: ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2023-04-11T05:55:15.230+0000: ** We suggest setting it to 'never'
2023-04-11T05:55:15.230+0000:
------
------
Enable MongoDB's free cloud-based monitoring service, which will then receive and display
metrics about your deployment (disk utilization, CPU, operation statistics, etc).
The monitoring data will be available on a MongoDB website with a unique URL accessible to you
and anyone you share the URL with. MongoDB may use this information to make product
improvements and to suggest MongoDB products and deployment options to you.
To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()
------
mongodb [direct: primary] admin>
What did you expect?
Connection to mongodb when we access using nodeport along with multiple end points.
What happened instead?
root@58bc44f91339:/# mongosh mongodb://adminuser:m127AKWoRG@10.1.0.4:30001,10.1.0.4:30002/admin?replicaSet=mongodb
Current Mongosh Log ID:64351b2539115d02752939b2
Connecting to:mongodb://<credentials>@10.1.0.4:30001,10.1.0.4:30002/admin?replicaSet=mongodb&appName=mongosh+1.8.0
MongoNetworkError: getaddrinfo ENOTFOUND mongodb-0.mongodb-svc.mytests.svc.cluster.local
Operator Information
- Operator Version: -0.7.8
- MongoDB Image used: docker.io/mongo:4.2.6,quay.io/mongodb/mongodb-agent:12.0.15.7646-1, quay.io/mongodb/mongodb-kubernetes-operator:0.7.8
Kubernetes Cluster Information
- Distribution
- Version- v1.25.8
- Image Registry location (quay, docker hub)
Additional context
connecting externally using nodeport doesn't work.
If possible, please include:
kubectl describe
output- yamls are already provided- yaml definitions for your objects - included already
- log files for the operator and database pods
2023-04-11T09:18:11.985+0000 I NETWORK [listener] connection accepted from 10.1.36.64:6658 #3428 (17 connections now open)
2023-04-11T09:18:11.987+0000 I NETWORK [listener] connection accepted from 10.1.0.4:31312 #3678 (25 connections now open)
2023-04-11T09:18:11.990+0000 I NETWORK [conn3678] received client metadata from 10.1.0.4:31312 conn3678: { driver: { name: "nodejs|mongosh", version: "5.1.0
" }, os: { type: "Linux", name: "linux", architecture: "x64", version: "5.15.0-1029-azure" }, platform: "Node.js v16.19.1, LE (unified)", version: "5.1.0|1.8.
0", application: { name: "mongosh 1.8.0" } }
2023-04-11T09:18:11.989+0000 I NETWORK [conn3428] received client metadata from 10.1.36.64:6658 conn3428: { driver: { name: "nodejs|mongosh", version: "5.1.
0" }, os: { type: "Linux", name: "linux", architecture: "x64", version: "5.15.0-1029-azure" }, platform: "Node.js v16.19.1, LE (unified)", version: "5.1.0|1.8
.0", application: { name: "mongosh 1.8.0" } }
2023-04-11T09:18:12.000+0000 I NETWORK [conn3678] end connection 10.1.0.4:31312 (24 connections now open)
2023-04-11T09:18:11.998+0000 I NETWORK [conn3428] end connection 10.1.36.64:6658 (16 connections now open)
2023-04-11T09:18:12.168+0000 I NETWORK [listener] connection accepted from 10.1.126.224:50954 #3429 (17 connections now open)
2023-04-11T09:18:12.169+0000 I NETWORK [listener] connection accepted from 10.1.126.224:50962 #3430 (18 connections now open)
2023-04-11T09:18:12.169+0000 I NETWORK [conn3430] received client metadata from 10.1.126.224:50962 conn3430: { driver: { name: "mongo-go-driver", version: "
v1.7.2+prerelease" }, os: { type: "linux", architecture: "amd64" }, platform: "go1.18.5", application: { name: "MongoDB Automation Agent v12.0.15.7646 (git: 2
5bb5320d7087c7aa24eb6118df217a028238723)" } }
2023-04-11T09:18:12.170+0000 I NETWORK [conn3429] received client metadata from 10.1.126.224:50954 conn3429: { driver: { name: "mongo-go-driver", version: "
v1.7.2+prerelease" }, os: { type: "linux", architecture: "amd64" }, platform: "go1.18.5", application: { name: "MongoDB Automation Agent v12.0.15.7646 (git: 2
5bb5320d7087c7aa24eb6118df217a028238723)" } }
2023-04-11T09:18:12.171+0000 I NETWORK [listener] connection accepted from 10.1.126.224:50970 #3431 (19 connections now open)
2023-04-11T09:18:12.171+0000 I NETWORK [conn3431] received client metadata from 10.1.126.224:50970 conn3431: { driver: { name: "mongo-go-driver", version: "
v1.7.2+prerelease" }, os: { type: "linux", architecture: "amd64" }, platform: "go1.18.5", application: { name: "MongoDB Automation Agent v12.0.15.7646 (git: 2
5bb5320d7087c7aa24eb6118df217a028238723)" } }
2023-04-11T09:18:12.181+0000 I ACCESS [conn3431] Successfully authenticated as principal __system on local from client 10.1.126.224:50970
2023-04-11T09:18:12.183+0000 I NETWORK [conn3429] end connection 10.1.126.224:50954 (18 connections now open)
2023-04-11T09:18:12.183+0000 I NETWORK [conn3430] end connection 10.1.126.224:50962 (17 connections now open)
2023-04-11T09:18:12.184+0000 I NETWORK [conn3431] end connection 10.1.126.224:50970 (16 connections now open)
2023-04-11T09:18:12.303+0000 I NETWORK [listener] connection accepted from 10.1.36.88:34104 #3679 (25 connections now open)
2023-04-11T09:18:12.303+0000 I NETWORK [listener] connection accepted from 10.1.36.88:34110 #3680 (26 connections now open)
2023-04-11T09:18:12.303+0000 I NETWORK [conn3679] received client metadata from 10.1.36.88:34104 conn3679: { driver: { name: "mongo-go-driver", version: "v1
.7.2+prerelease" }, os: { type: "linux", architecture: "amd64" }, platform: "go1.18.5", application: { name: "MongoDB Automation Agent v12.0.15.7646 (git: 25b
b5320d7087c7aa24eb6118df217a028238723)" } }
2023-04-11T09:18:12.303+0000 I NETWORK [conn3680] received client metadata from 10.1.36.88:34110 conn3680: { driver: { name: "mongo-go-driver", version: "v1
.7.2+prerelease" }, os: { type: "linux", architecture: "amd64" }, platform: "go1.18.5", application: { name: "MongoDB Automation Agent v12.0.15.7646 (git: 25b
b5320d7087c7aa24eb6118df217a028238723)" } }
2023-04-11T09:18:12.305+0000 I NETWORK [listener] connection accepted from 10.1.36.88:34120 #3681 (27 connections now open)
2023-04-11T09:18:12.306+0000 I NETWORK [conn3681] received client metadata from 10.1.36.88:34120 conn3681: { driver: { name: "mongo-go-driver", version: "v1
.7.2+prerelease" }, os: { type: "linux", architecture: "amd64" }, platform: "go1.18.5", application: { name: "MongoDB Automation Agent v12.0.15.7646 (git: 25b
b5320d7087c7aa24eb6118df217a028238723)" } }
2023-04-11T09:18:12.319+0000 I ACCESS [conn3681] Successfully authenticated as principal __system on local from client 10.1.36.88:34120
2023-04-11T09:18:12.319+0000 I NETWORK [conn3680] end connection 10.1.36.88:34110 (26 connections now open)
2023-04-11T09:18:12.320+0000 I NETWORK [conn3681] end connection 10.1.36.88:34120 (25 connections now open)
2023-04-11T09:18:12.320+0000 I NETWORK [conn3679] end connection 10.1.36.88:34104 (24 connections now open)
Im also looking at externally accesing mongodb, did you find a solution?
Im also looking at externally accesing mongodb, did you find a solution?
Still no findings, let me also know if you find any solution. in my case i can able to access with single end point.
I couldn't get NodePort to work correctly, but I got it working with a LoadBalancer with this tutorial: https://antonputra.com/kubernetes/how-to-install-mongodb-on-kubernetes/#configure-external-access-on-aws
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.
This issue was closed because it became stale and did not receive further updates. If the issue is still affecting you, please re-open it, or file a fresh Issue with updated information.
I have the same issue, I can't connect to my database with MongoDB Compas