Expose pod to a particular pre-determined IP address

4/13/2020

I'm looking to expose individual pods HTTP. The trick here is that the pod in question needs to know its externally valid IP address, and so in order to configure that ahead of time, I have to have certainty on the external IP address that I'm exposing it by.

Currently I'm trying to expose in this way:

kubectl expose pod my-pod --type=LoadBalancer --name=lb-http --external-ip=$IP --port=80 --target-port=30000

But I'm thinking that the --external-ip flag isn't operating as I intend, as my GKE cluster ends up with a different endpoint IP address.

Is there a way to expose an individual pod to a particular pre-determined IP address?

-- FrobberOfBits
kubernetes
networking

2 Answers

4/14/2020

Not possible via LoadBalancer type service. However you can use nginx ingress controller to expose all of your pods on same static IP and apply ingress rules for path and host based routing.This doc demonstrates how to assign a static-ip to an Ingress on through the Nginx controller.

You can achieve the same with GKE ingress as well. Here is the doc on how to do that.

-- Arghya Sadhu
Source: StackOverflow

4/14/2020

You can't pre-assign an IP. It will go create a new GCP LB and then stash the IP/hostname in the Status substruct. Then you take that and put it in your config file or whatever.

-- coderanger
Source: StackOverflow