We are in the process of migrating from CloudRun to GKE Autopilot. We have the same exact environment variables and the LoadBalancer service for the workload has the same port configuration as the CloudRun service. We created a Workload Identity and binded it to a custom IAM account. We have whitelisted the external ip of the LoadBalancer in atlas. The workload tries to login to MongoDB (with credentials we verified to be correct), but around a minute later I get the following error message and following that the pod gets restarted:

"MongoServerSelectionError: Client network socket disconnected before secure TLS connection was established
        at Timeout._onTimeout (/app/node_modules/mongodb/lib/core/sdam/topology.js:438:30)
        at listOnTimeout (internal/timers.js:554:17)
        at processTimers (internal/timers.js:497:7) {"
"reason: TopologyDescription {"
"type: 'ReplicaSetNoPrimary',"
setName: null,
maxSetVersion: null,
maxElectionId: null,
 servers: Map {
 '<redacted>-shard-00-00.<redacted>.mongodb.net:27017' => [ServerDescription]
 '<redacted>-shard-01-00.<redacted>.mongodb.net:27017' => [ServerDescription]
 '<redacted>-shard-02-00.<redacted>.mongodb.net:27017' => [ServerDescription]
stale: false,
compatible: true,
compatibilityError: null,
logicalSessionTimeoutMinutes: null,
heartbeatFrequencyMS: 10000,
localThresholdMS: 15,
commonWireVersion: null

To me it looks like it is able to reach out to the internet as it was able to get the Map of shard servers, and I am able to ping those shard servers, but I don't know if there is a precomputed list that Mongo software is pulling from.

EDIT: I see https://stackoverflow.com/questions/66110855/cant-connect-to-mongoclient but it makes no sense that the cluster was configured incorrectly to not designate a primary shard because the connection works with the same container in CloudRun.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.