从本地主机连接到kubernetes集群中的mongodb副本集

时间:2019-06-12 01:31:59

标签: mongodb kubernetes

我已经将mongo数据库建立到kubernetes集群中。 mongo有两个实例mongo-0mongo-1

我想通过Studio T3CompassNodeJs script连接我的实例,但是我有一些问题:D

首先,我正在转发两个端口

kubectl port-forward --namespace=staging mongo-0 27017:27017

kubectl port-forward --namespace=staging mongo-1 27018:27017

然后我尝试通过以下方式进行连接:

Studio T3我的mongo实例上有以下日志

2019-06-11T23:16:13.535+0000 I NETWORK  [listener] connection accepted from 127.0.0.1:50002 #38 (2 connections now open)
2019-06-11T23:16:13.850+0000 I NETWORK  [conn38] received client metadata from 127.0.0.1:50002 conn38: { driver: { name: "mongo-java-driver|legacy", version: "019.1.0-FINAL-1091-g366aa8c04a" }, os: { type: "Darwin", name: "Mac OS X", architecture: "x86_64", version: "10.14.5" }, platform: "Java/Oracle Corporation/1.8.0_202-b08" }
2019-06-11T23:30:09.037+0000 I NETWORK  [conn38] end connection 127.0.0.1:50002 (2 connections now open)

登录GUI

Connection failed.

SERVER [x.x.x.x:27017] (Type: UNKNOWN) 
|_/ Connection error (MongoSocketOpenException): Exception opening socket
|____/ I/O error: connect timed out

SERVER [x.x.x.x:27017] (Type: UNKNOWN) 
|_/ Connection error (MongoSocketOpenException): Exception opening socket
|____/ I/O error: connect timed out

Details:
Timed out after 30000 ms while waiting for a server that matches com.mongodb.client.internal.MongoClientDelegate$1@318b89b8. Client view of cluster state is {type=REPLICA_SET, servers=[{address=x.x.x.x:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.SocketTimeoutException: connect timed out}}, {address=x.x.x.x:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.SocketTimeoutException: connect timed out}}]

现在有了基本的NodeJs script

2019-06-12T01:09:04.692+0000 I NETWORK  [listener] connection accepted from 127.0.0.1:41320 #1419 (3 connections now open)
2019-06-12T01:09:04.980+0000 I NETWORK  [conn1419] received client metadata from 127.0.0.1:41320 conn1419: { driver: { name: "nodejs", version: "3.2.7" }, os: { type: "Darwin", name: "darwin", architecture: "x64", version: "18.6.0" }, platform: "Node.js v10.15.0, LE, mongodb-core: 3.2.7" }
2019-06-12T01:09:05.100+0000 I NETWORK  [conn1419] end connection 127.0.0.1:41320 (2 connections now open)

节点返回此错误

{ MongoNetworkError: failed to connect to server [x.x.x.x:27017] on first connect [MongoNetworkError: connection timed out]
    at Pool.<anonymous> (/Volumes/Work/test/mongo/node_modules/mongodb-core/lib/topologies/server.js:431:11)
    at Pool.emit (events.js:182:13)
    at connect (/Volumes/Work/test/mongo/node_modules/mongodb-core/lib/connection/pool.js:557:14)
    at makeConnection (/Volumes/Work/test/mongo/node_modules/mongodb-core/lib/connection/connect.js:39:11)
    at callback (/Volumes/Work/test/mongo/node_modules/mongodb-core/lib/connection/connect.js:261:5)
    at Socket.err (/Volumes/Work/test/mongo/node_modules/mongodb-core/lib/connection/connect.js:286:7)
    at Object.onceWrapper (events.js:273:13)
    at Socket.emit (events.js:182:13)
    at Socket._onTimeout (net.js:453:8)
    at ontimeout (timers.js:436:11)
  name: 'MongoNetworkError',
  errorLabels: [ 'TransientTransactionError' ],
  [Symbol(mongoErrorContextSymbol)]: {} }

我真的不明白为什么会有这些超时。 可能是因为在第一次连接后,我的本地连接器正试图通过公共mongo ip到达,所以我用x.x.x.x代替了该连接器,因此无法建立连接。

0 个答案:

没有答案