-
Type: Task
-
Resolution: Works as Designed
-
Priority: Major - P3
-
None
-
Affects Version/s: 3.1.4
-
Component/s: None
-
Environment:GKE,ubuntu
-
Empty show more show less
我參照[MongoDB Deployment Demo for Kubernetes on GKE|https://github.com/pkdone/gke-mongodb-demo]在我的GCP Project架設了MongoDB。
Replica Set Member使用Kubernetes Internal Domain Name:
mongod-0.mongods-svc-headless.default.svc.cluster.local:27017
mongod-1.mongods-svc-headless.default.svc.cluster.local:27017
mongod-2.mongods-svc-headless.default.svc.cluster.local:27017
使用NodePort Service Expose之後,使用Mongo Shell連線可以建立[1]。
但使用MongoDB Node.JS Driver進行連線會出現MongoDB Node.JS將K8S Internal Domain Name當作Host連線的狀況[2],導致Node.JS不能對K8S所架設的MongoDB連線。
只能使用K8S各節點的External IP與NodePort當作Replica Set Member。
例如:
K8S Node1 External IP: 111.111.111.111:30001
K8S Node2 External IP: 222.222.222.222:30002
K8S Node3 External IP: 333.333.333.333:30003
Replica Set Members: {host1: 111.111.111.111:30001, host2: 222.222.222.222:30002, host3: 333.333.333.333:30003}
只有這樣設定才能讓MongoDB Node.JS連線。
這很不合理,使用K8S Internal Domain Name進行Replica Set配置,Mongo Shell可以連線,然而MongoDB Node.JS不能連線。
[1]: mongo-shell-connect
[2]: mongo-nodejs-connect
- is related to
-
SERVER-36603 Support for multiple hostnames and IPs in MongoDB replica sets for high availability
- Backlog