Uploaded image for project: 'Node.js Driver'
  1. Node.js Driver
  2. NODE-1711

使用K8S透過Stateful創建MongoDB的連線問題

    • Type: Icon: Task Task
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 3.1.4
    • Component/s: None
    • Environment:
      GKE,ubuntu

      我參照[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

        1. mongo-shell-connect.png
          mongo-shell-connect.png
          209 kB
        2. mongo-nodejs-connect.png
          mongo-nodejs-connect.png
          86 kB

            Assignee:
            daniel.aprahamian@mongodb.com Daniel Aprahamian (Inactive)
            Reporter:
            d0972058277 yu
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: