DigitalOcean Kubernetes (DOKS) is a managed Kubernetes service. Deploy Kubernetes clusters with a fully managed control plane, high availability, autoscaling, and native integration with DigitalOcean Load Balancers and volumes. DOKS clusters are compatible with standard Kubernetes toolchains and the DigitalOcean API and CLI.
When you migrate an application from a Kubernetes cluster to another, you can also migrate the associated load balancer service to the target cluster. Doing so preserves the external IP address of the load balancer that your application’s DNS record points to.
To migrate a load balancer, you first disown the load balancer service from the existing service and then reference the load balancer’s ID in the service of the new cluster. Disowning the load balancer from the existing service turns all mutating actions, such as load balancer creates, updates and deletes, that are driven through the service into no-ops.
Use the following workflow to migrate a load balancer from one cluster to another. Suppose you have a load balancer service named app
that is associated with a production-v1
cluster and you want to move it to another cluster production-v2
.
Ensure that there are no load balancer-related error events in your existing service by running the following command:
kubectl describe service <service-name>
Fix any reported errors to bring the service into a stable state.
Disown the load balancer by adding the following annotation in the service config file and setting it to true
:
kind: Service
apiVersion: v1
metadata:
name: app
annotations:
kubernetes.digitalocean.com/load-balancer-id: c16b0b29-217b-48eb-907e-93cf2e01fb56
service.kubernetes.io/do-loadbalancer-disown: "true"
spec:
selector:
name: app
ports:
- name: http
protocol: TCP
port: 80
type: LoadBalancer
load-balancer-id
is set by the DigitalOcean cloud control manager when you first provision the load balancer.Use kubectl apply
to apply the update to the config file. Verify that the change applied correctly by running kubectl describe service <service-name>
again.
Once the change applies, all mutating requests directed at the load balancer and driven through the service are ignored.
Create a new service config file in the production-v2
cluster to use the load-balancer-id
from the previous service config file.
kind: Service
apiVersion: v1
metadata:
name: app
annotations:
kubernetes.digitalocean.com/load-balancer-id: c16b0b29-217b-48eb-907e-93cf2e01fb56
spec:
selector:
name: app
ports:
- name: http
protocol: TCP
port: 80
type: LoadBalancer
If you have other load balancer configuration annotations that you want to transfer to the new service, add them to the config file.
Check the service events again to ensure that the DigitalOcean cloud control manager has finished reconciling the update.
Once complete, the load balancer is owned by the new service and the traffic is routed to the new cluster.
Delete the service from the old cluster or change it to another Kubernetes service type.