How to Migrate Load Balancers

DigitalOcean Kubernetes (DOKS) is a managed Kubernetes service that lets you deploy Kubernetes clusters without the complexities of handling the control plane and containerized infrastructure. Clusters are compatible with standard Kubernetes toolchains, integrate natively with DigitalOcean Load Balancers and volumes, and can be managed programmatically using the API and command line. For critical workloads, add the high-availability control plane to increase uptime with 99.95% SLA.


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.

Note
The new service’s cluster must reside in the same VPC as the original service for the load balancer ownership to be transferred successfully. For more information, see the VPC documentation.

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.

  1. 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.

  2. 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
      
            
        
    
Note
The 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.

  1. 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.

  2. 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.

  3. Delete the service from the old cluster or change it to another Kubernetes service type.