Kubernetes + GCP TCP Load balancing: How can I assign a static IP to a Kubernetes Service?

2/2/2020

I want to assign a static (i.e. non-ephemeral) regional IP to a Kubernetes service. Currently the service is of type "LoadBalancer", which GCP exposes as a regional TCP load balancer. By default the IP address of the forwarding rule is ephemeral. Is there any way I can use an existing static ip or to assign my own address by name (as is possible with Ingress/HTTP(S) Load Balancer)?

I have also tried to create my own forwarding rule with a custom static regional IP using the NodePort of the service. I have only succeeded to build the forwarding rule using the actual NodePort, but how does the Kubernetes/GCP-magic work that maps port 80 to the NodePort when using type "LoadBalancer"?

-- Florian
google-cloud-platform
google-kubernetes-engine
kubernetes

1 Answer

2/2/2020

I have found a way to set the static IP. After that I needed to delete the service object and re-create it.

- apiVersion: v1
  kind: Service
  spec:
    loadBalancerIP: '<static ip>'

But the second part of my question I am still curious about

-- Florian
Source: StackOverflow