Transferring a Floating IP Between Services
2 minute read
This tutorial shows how to transfer an existing floating IP from one Kubernetes LoadBalancer service to another — without releasing and reassigning the IP.
Use case: A new version of a service should be reachable under the same IP, e.g. during a blue/green deployment or a service rename.
Prerequisites
- An existing LoadBalancer service with an assigned floating IP
kubectlaccess to the cluster
Step 1 — Get the current floating IP
kubectl get svc <old-service-name>
The floating IP is shown in the EXTERNAL-IP column. Alternatively:
kubectl get svc <old-service-name> -o jsonpath='{.metadata.annotations.loadbalancer\.openstack\.org/load-balancer-address}'
Note the IP for the following steps.
Step 2 — Reserve the floating IP on the old service
If the keep-floatingip annotation is not yet set, add it now:
kubectl annotate svc <old-service-name> \
loadbalancer.openstack.org/keep-floatingip="true"
Step 3 — Delete the old service
kubectl delete svc <old-service-name>
The load balancer in OpenStack is removed, but the floating IP remains reserved.
Step 4 — Create the new service with the floating IP
In the new service manifest, reference the floating IP via spec.loadBalancerIP and the annotations:
apiVersion: v1
kind: Service
metadata:
name: <new-service-name>
annotations:
loadbalancer.openstack.org/keep-floatingip: "true"
loadbalancer.openstack.org/load-balancer-address: <FloatingIP>
spec:
type: LoadBalancer
loadBalancerIP: <FloatingIP>
selector:
app: <new-app-label>
ports:
- port: 80
targetPort: 8080
kubectl apply -f <new-service>.yaml
Step 5 — Verify the assignment
kubectl get svc <new-service-name>
After 1–2 minutes, the floating IP appears in the EXTERNAL-IP column. The CCM may need a brief moment to provision the new load balancer and assign the IP.
Notes
- There will be a brief downtime between deleting the old service and the new service becoming ready.
keep-floatingip: "true"should remain set on the new service to retain the IP on future deletions.- If the IP is no longer known after deleting the old service, please open a support ticket in the customer portal.