Skip to main content

How do I keep a load balancer's IP address when I recreate a Service?

Syself support For release

A LoadBalancer Service can use Hetzner Primary IPs that you own. A Primary IP stays in your project when the Service and its load balancer are deleted, and a new Service with the same annotations gets the same address.

  1. Create a Primary IP with the assignee type load_balancer in the location of the load balancer, with auto_delete off.

  2. Set its ID on the Service when you create it:

    yaml
    				metadata:
      annotations:
        load-balancer.hetzner.cloud/location: fsn1
        load-balancer.hetzner.cloud/public-net-ipv4: "4711"
        load-balancer.hetzner.cloud/public-net-ipv6: "4712"
    			

The value is the ID of the Primary IP, not the address. Each annotation works without the other.

An existing load balancer cannot move to a Primary IP. The annotations are only read when the load balancer is created, so delete and recreate the Service once. Its address changes that one time.

If you only edit a Service, you do not need this: a load balancer keeps its addresses as long as the Service exists, also through cluster upgrades and a change of the load balancer type.

For the API call that creates the Primary IP and the error events, see Keep the address with a Primary IP.

Still stuck?

Prepare your case, then email us.