Florian
Florian

Reputation: 382

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

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"?

Upvotes: 0

Views: 228

Answers (1)

Florian
Florian

Reputation: 382

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

Upvotes: 1

Related Questions