我正在连接在GCP Kubernetes集群上运行的Nodejs应用程序。以前,当我启用VPC对等连接并且使用连接字符串(专用)时,它工作正常。建议在Atlas仪表板上:
mongodb + srv://(用户名):(密码)@ <集群名称> -pri.m6tkv.gcp.mongodb.net/ <数据库名称>?retryWrites = true&w = majority
我按照本教程进行了设置:https://docs.atlas.mongodb.com/security-vpc-peering/
我无法理解,因为使用此配置我的应用已经运行了一段时间。但是有一天,我的GCP集群中的Pod上运行的应用无法连接。
那是错误消息:
Connected mongodb failed MongoNetworkError: failed to connect to server [<cluster_name>-00-00-pri.m6tkv.gcp.mongodb.net:27017] on first connect [MongoNetworkError: connection timed out
at connectionFailureError (/app/node_modules/mongoose/node_modules/mongodb/lib/core/connection/connect.js:406:14)
at TLSSocket.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb/lib/core/connection/connect.js:294:16)
at Object.onceWrapper (events.js:299:28)
at TLSSocket.emit (events.js:210:5)
at TLSSocket.Socket._onTimeout (net.js:469:8)
at listOnTimeout (internal/timers.js:531:17)
at processTimers (internal/timers.js:475:7) {name: 'MongoNetworkError' }] at Pool.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb/lib/core/topologies/server.js:438:11)
at Pool.emit (events.js:210:5)
at /app/node_modules/mongoose/node_modules/mongodb/lib/core/connection/pool.js:562:14
at /app/node_modules/mongoose/node_modules/mongodb/lib/core/connection/pool.js:1009:9
at /app/node_modules/mongoose/node_modules/mongodb/lib/core/connection/connect.js:31:7
at callback (/app/node_modules/mongoose/node_modules/mongodb/lib/core/connection/connect.js:264:5)
at TLSSocket.<anonymous> (/app/node_modules/mongoose/node_modules/mongodb/lib/core/connection/connect.js:294:7)
at Object.onceWrapper (events.js:299:28)
at TLSSocket.emit (events.js:210:5)
at TLSSocket.Socket._onTimeout (net.js:469:8)
at listOnTimeout (internal/timers.js:531:17)
at processTimers (internal/timers.js:475:7)
我切换回旧的连接(标准),我的应用程序又可以工作了。连接字符串:
mongodb + srv://(用户名):(密码)@ <集群名称> .m6tkv.gcp.mongodb.net / <数据库名称>?retryWrites = true&w = majority
因此通过VPC对等连接存在问题,我找不到任何线索。