<p>I have a <code>kubernetes</code> cluster having 5 nodes, deployed on aws using <a href="https://github.com/kubernetes/kops" rel="nofollow noreferrer">kops</a>.</p>
<p>I have a setup a load balancer and <code>ingress-nginx</code> controller for reverse proxy.</p>
<p>So, all incoming request come to a <em>single ip</em> which is of the load balancer.</p>
<p>I have an service <code>admin-srv</code> inside the cluster which forwards request to two <code>pods</code>.</p>
<p>The problem is whenever I make request to some domain <code>example.com</code> from these pods, the source ip assigned is random and picked from any <code>node</code></p>
<p>So, one time I hit request it is something like <code>5.1...</code>, again if hit the ip becomes <code>5.2....</code></p>
<p><em>The domain that I am calling <code>example.com</code> they need one <code>ip</code> that would not change and they will whitelist that.</em></p>
<p><em><strong>How it can be achieved?</strong></em></p>

<p>You have to set the NAT gateway for this scenario.</p>
<p>So using the NAT gateway all the out bound request will be diverted using the one VM and you will get single IP for the out bound traffic also.</p>
<p>You can read more about the <strong>NAT</strong> : <a href="https://cloud.google.com/nat/docs/overview" rel="nofollow noreferrer">https://cloud.google.com/nat/docs/overview</a></p>
<p><strong>AWS</strong> : <a href="https://docs.aws.amazon.com/vpc/latest/userguide/vpc-nat-gateway.html" rel="nofollow noreferrer">https://docs.aws.amazon.com/vpc/latest/userguide/vpc-nat-gateway.html</a>
<a href="https://docs.aws.amazon.com/vpc/latest/userguide/VPC_Scenario2.html" rel="nofollow noreferrer">https://docs.aws.amazon.com/vpc/latest/userguide/VPC_Scenario2.html</a></p>
<p>If you are one the GKE you can take a look on this example of terraform : <a href="https://registry.terraform.io/modules/GoogleCloudPlatform/nat-gateway/google/latest/examples/gke-nat-gateway" rel="nofollow noreferrer">https://registry.terraform.io/modules/GoogleCloudPlatform/nat-gateway/google/latest/examples/gke-nat-gateway</a></p>
