How to configure Kubenetes to make external requests going from a static IP

6/10/2019

I have a bunch of pods and corresponding cluster IP services running in a Kubenetes cluster. I use an Ingress controller to route incoming traffic to these workloads.

Now, when I make an external request from within a workload, I would like those requests to go out from a static IP.

  1. Are both incoming and outgoing traffic handled via the same network interface?

  2. How do I set a static IP for my outgoing requests from a pod

Thanks in advance.

-- Charlie
kubernetes
kubernetes-ingress
load-balancing
routing
static-ip-address

2 Answers

6/11/2019

Some research showed me the following method and it worked:

  1. Create a new node pool with a specific label (lets say ip=static)

  2. Deploy the workload with the following selector

     nodeSelector:
       ip: static
  3. Through VPC Network, reserve an external static IP

  4. Assign this IP to the VM which is used by the new node pool

However, as the @user578582 has mentioned, when the scaling is done, I will have to use a NAT gateway to make all the outbound traffic to go from a static IP under this configuration.

-- Charlie
Source: StackOverflow

6/10/2019

If you're on AWS or GKE the only way to get a static outbound from an (autoscaling) node pool is via a NAT gateway. On GKE you are also required to have private nodes (no public ips).

Kubernetes ingress, at least in GKE, is treated separately from egress and is a different load balancer.

https://cloud.google.com/nat/docs/gke-example

-- eamon1234
Source: StackOverflow