How do I keep a load balancer's IP address when I recreate a Service?
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.
Create a Primary IP with the assignee type
load_balancerin the location of the load balancer, withauto_deleteoff.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.
Related questions
