Let’s say you want to migrate a service in GKE from one cluster to another (including between Standard and Autopilot clusters), and keep the same external IP while you do. DNS might be the ideal way to update your service address, for whatever reason you need to keep the IP the same. Fortunately, it is possible to preserve the IP and assign it to a new service in a different cluster in Kubernetes.
Migrating an Ingress IP
Ingress (L7 load balancer) IPs in GKE are global. The first step to migrating an IP between clusters is to promote the ephemeral IP attached to an existing Ingress into a global static IP in the following way:
gcloud compute addresses create ingress-ip \
Make sure it is now shown in this list as “Static”. Double check this, because if you perform the next step without that IP being static, you won’t be able to get it back.
Once the IP is converted, you can delete the ingress resource in the old GKE cluster (
kubectl delete ing INGRESS_NAME), and create a new one in the new cluster. The deletion is needed before you can re-assign the IP to a new resource.
When creating the new Ingress, you can assign the static IP that you created above from the old Ingress to the new one by referring to its resource name like so:
Migrating a Load Balancer IP
For Services of type
LoadBalancer (L4 load balancers), the steps are similar, but you instead convert the ephemeral IP attached to the load balancer into a regional static IP, of the same region of your cluster.
gcloud compute addresses create lb-ip \
As with Ingress, make sure the IP is now shown in this list as “Static”. Double check this, because if you perform the next step without that IP being static, you won’t be able to get it back.
Once the IP is static, you can delete the service resource in the old GKE cluster (
kubectl delete svc SERVICE_NAME), and create a new one in the new cluster. The deletion is needed before you can re-assign the IP to a new resource.
When creating the new Service of type
LoadBalancer you specify the IP itself (referring to the IP address, not the resource name) in the
- port: 80