Question

How to set static IP for loadbalancer in Kubernetes?

Posted November 27, 2018 22.4k views
Configuration ManagementLoad BalancingDeploymentHigh AvailabilityKubernetes

Imagine a following situation: I have a Kubernetes cluster and I want to have a statically assigned IP to LoadBalancers within those clusters. How or where I can obtain those static IPs?

Whenever I tear down Kubernetes Pods, IPs are assigned dynamically, which is fine, but if I want to assign the Kubernetes LoadBalancer a static IP, I have no way of knowing which IP address should be set, hence I need to change DNS records every time Kubernetes Master assigns a new IP address.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
7 answers

What if we deleted the cluster and reuse the loadbalancer in the newly created cluster. I couldn’t find a way to achieve this. I tried to specify static IP in the service level but no matter what kubernetes creates a new LB. Cannot use the existing one.

@PeterBocan How did you solve this? I was thinking that I might grab a floating IP, standup a droplet and set it up with nginx to proxy to my K8S load balancer. This way when the K8S IP changes, I only need to modify my proxy server and not DNS records.

There seems like there should be a better way.

Same problem here as @fkucuk . DigitalOcean are you listening? How can we solve this problem?

We are forced to delete and recreate the cluster because we’re still facing the “deleting and recreating a NFS pv will break mounting that NFS PV forever” problem. This when NFS breaks, we have to re-setup everying from zero.

And it sucks when all our external clients break because we have to update our DNS to point to the new LoadBalancer IP.

Same problem as here: https://www.digitalocean.com/community/questions/how-to-reuse-do-loadbalancer-previously-created-through-kubernetes
Also see https://www.digitalocean.com/community/questions/how-to-update-to-1-15-k8s-in-do-managed-k8s where users will run into this very problem when upgrading their clusters.

Same here. I am using helm delete sometimes which tears down all the cluster resources. When I recreate the cluster, I get a new IP address for the LB. This is annoying because I have to update the DNS entries each time. It would be nice to have a fixed IP feature, in which we can specify a fixed IP address in the LB (or ingress) configuration.

same here.
I’m using helms, and its a Hugh problem for me

I dunno if this is too late, probably so, but in your Service yaml specify something like this:

loadBalancerIP: <your desired external ip>
type: LoadBalancer
  • How do you reserve that desired external ip?

  • I’m trying to solve this problem too. Great find @quackerjeff

    According to the Kubernetes docs, the loadBalancerIP tag may or may not be implemented by the service provider, in this link link, under the section “Type LoadBalancer” refer to the third paragraph, which states:

    “Some cloud providers allow you to specify the loadBalancerIP. In those cases, the load-balancer is created with the user-specified loadBalancerIP. If the loadBalancerIP field is not specified, the loadBalancer is set up with an ephemeral IP address. If you specify a loadBalancerIP but your cloud provider does not support the feature, the loadbalancerIP field that you set is ignored.”

    Is there any indication if DigitalOcean supports this feature?

    If DigitalOcean is listening: For our $10 monthly Load Balancer fee (or an additional fee if necessary), we would like a reserved IP address that we can specify in the loadBalancerIP field to, in essence, configure a static IP address for our service.

    Thanks all!