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

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

    XMLWordPrintable

Details

    • Task
    • Status: Closed
    • Major - P3
    • Resolution: Works as Designed
    • 3.1.4
    • None
    • None
    • GKE,ubuntu

    Description

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

      Attachments

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

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: