<p>I have an issue with trying to deploy my containerized app to GKE. It is not able to reach my MongoDB Atlas cluster. Running the Docker container locally creates no issues and works perfectly. I am by no means an expert in Docker or Kubernetes, but I am assuming it is something to do with the DNS name resolution.</p>

<p>I have followed this tutorial - <a href="https://cloud.google.com/kubernetes-engine/docs/tutorials/hello-app" rel="nofollow noreferrer">Deploying a containerized web application</a>, with an addition of adding an EXTERNAL-IP of the LoadBalancer to my 'Network Access' IP Whitelist in the MongoDB Atlas console and using port mapping 443 -> 8443 since I am using HTTPS.</p>

<p>Only logs that my app is able to produce before failing:</p>

<pre><code>(mongodb): 2020/05/30 15:07:39 logger.go:96: 2020-05-30T15:07:39Z 
[error] Failed to connect to mongodb. Check if mongo is running...
(mongodb): 2020/05/30 15:07:39 logger.go:132: 2020-05-30T15:07:39Z 
[fatal] server selection error: server selection timeout, current 
topology: { Type: ReplicaSetNoPrimary, Servers: [{ Addr: biomas- 
cluster-shard-&lt;removed&gt;.azure.mongodb.net:27017, Type: Unknown, 
State: Connected, Average RTT: 0, Last error: connection() : 
connection(biomas-cluster-shard-&lt;removed&gt;.azure.mongodb.net:27017[-180]) incomplete read of message 
header: EOF }, { Addr: biomas-cluster-shard-&lt;removed&gt;.azure.mongodb.net:27017, Type: Unknown, State: Connected, Average RTT: 0, Last error: connection() : connection(biomas-cluster-shard-&lt;removed&gt;.azure.mongodb.net:27017[-181]) incomplete read of message header: EOF }, { Addr: biomas-cluster-shard-&lt;removed&gt;.azure.mongodb.net:27017, Type: Unknown, State: Connected, Average RTT: 0, Last error: connection() : connection(biomas-cluster-shard-&lt;removed&gt;.azure.mongodb.net:27017[-179]) incomplete read of message header: EOF }, ] }
</code></pre>

<p>If there is a simple workaround with to this, that would be preferred since the app is in the development stage still, so I just need a basically working application using the said technologies.</p>

<p>The full workflow:</p>

<p>Android App -> Golang API running on Docker -> MongoDB Atlas</p>

<p>Thanks</p>

<p>Exactly as @Marc point, your traffic got out with EXTERNAL-IP of your worker nodes, not your load balancer.</p>
<p>To find nodes EXTERNAL-IP IPs use:</p>
<pre class="lang-sh prettyprint-override"><code>kubectl get nodes -owide
</code></pre>
<p>To be more precise and output only IPs use (taken from <a href="https://kubernetes.io/docs/reference/kubectl/cheatsheet/" rel="nofollow noreferrer">kubectl Cheat Sheet</a>):</p>
<pre class="lang-sh prettyprint-override"><code>kubectl get nodes -o jsonpath='{.items[*].status.addresses[?(@.type==&quot;ExternalIP&quot;)].address}'
</code></pre>
<p>Next whitelist those IPs and you should be good, but keep in mind that after Kubernetes upgrade or cluster scaling the IPs might change, so I recommend using <a href="https://cloud.google.com/nat/docs/overview" rel="nofollow noreferrer">Cloud NAT</a> to always have the same IP for your outgoing traffic.</p>
