Help Center/ Cloud Container Engine/ User Guide/ Network/ Ingresses/ Migrating Data from a Bring-Your-Own Nginx Ingress to a LoadBalancer Ingress
Updated on 2025-01-07 GMT+08:00

Migrating Data from a Bring-Your-Own Nginx Ingress to a LoadBalancer Ingress

This section describes how to migrate data from a bring-your-own Nginx ingress to a LoadBalancer ingress.

LoadBalancer ingresses are implemented based on Huawei Cloud ELB. LoadBalancer ingresses offer better traffic management compared to bring-your-own Nginx ingresses because of the following advantages:

  • Fully managed and O&M-free: ELB is a fully managed cloud service that requires no worker node, making it completely O&M-free.
  • High availability: ELB enables active-active disaster recovery within a city across AZs. This ensures seamless traffic switchover in the event of a failure. Dedicated load balancers provide a comprehensive health check system to ensure that incoming traffic is only routed to healthy backend servers, improving the availability of your applications.
  • Auto scaling: ELB can automatically scale to handle traffic spikes.
  • Ultra-high performance: A single load balancer supports up to 1 million queries per second and tens of millions of concurrent connections.
  • Integration with cloud services: ELB can run with various cloud services, such as WAF.
  • Hot updates of configurations: Configuration changes can be updated in real-time without requiring a process reload. This helps to prevent disruptions to persistent connections.

Example Scenarios

A company is using a CCE cluster on Huawei Cloud to run their services. They have set up ingress forwarding rules using their NGINX Ingress Controller, which includes domain-based and URL-based forwarding rules. Their services are accessible externally through a DNS domain name. When a client requests access to the domain name example.com, Nginx Ingress forwards the requests to the pod associated with the Service based on the forwarding rules created on the ingress.

To develop services, the company must transfer their data from Nginx ingress to a LoadBalancer ingress. To maintain service stability, they want to keep the DNS domain name and IP addresses of their backend servers unchanged. To meet this requirement, you can configure LoadBalancer ingress rules in the CCE cluster to preserve the previous forwarding rules. Then, configure weighted DNS records to transfer data from the Nginx ingress to the LoadBalancer ingress.

  • Migrate data during off-peak hours.
  • You will be billed for using load balancers. For details, see Billing Overview.

Configuring the Target LoadBalancer Ingress

  1. Create an ingress for migration and route it to the original backend service.

    In this example, an existing load balancer is used to create an ingress, and the elbingress.yaml is for reference only. You can also choose to automatically create a load balancer associated with the ingress. For more information, see Creating a LoadBalancer Ingress Using kubectl.
    apiVersion: networking.k8s.io/v1
    kind: Ingress 
    metadata: 
      name: ingress-test
      annotations: 
        kubernetes.io/elb.id: <your_elb_id>  # Replace it with the ID of your existing load balancer.
        kubernetes.io/elb.ip: <your_elb_ip>  # Replace it with the IP of your existing load balancer.
        kubernetes.io/elb.class: performance  # A dedicated load balancer is used.
        kubernetes.io/elb.port: '80' 
    spec:
      rules: 
      - host: 'example.com'            # Replace it with your domain name.
        http: 
          paths: 
          - path: '/'
            backend: 
              service:
                name: <your_service_name>  # Replace it with the name of your target Service, which is the same as the Service associated with the original Nginx ingress.
                port: 
                  number: 8080             # Replace 8080 with the port number of your target Service.
            property:
              ingress.beta.kubernetes.io/url-match-mode: STARTS_WITH
            pathType: ImplementationSpecific
      ingressClassName: cce  

  2. Run the following command to create the ingress:

    kubectl apply -f elbingress.yaml

Redirecting Traffic to the LoadBalancer Ingress

Before redirecting traffic, ensure you have created record A to map the service domain name to the public IP address of the company's Nginx ingress. You can configure weighted DNS records to transfer data from the Nginx ingress to the LoadBalancer ingress.

Figure 1 Using DNS to redirect traffic

To redirect traffic, do as follows:

  1. Access the public zone list.
  2. On the Public Zones page, click the domain name (example.com) of the public zone.
  3. The Record Sets page is displayed. You can find an A record, which contains the public IP address of the Nginx ingress. Change the weight of the A record to 9.
  4. Add an A record set. To do so, click Add Record Set, and set Value to the public IP address of the target LoadBalancer ingress and Weight to 1.

    Figure 2 Adding a record set

  5. Gradually increase the weight of the DNS record for the LoadBalancer ingress to 100% without affecting any services.

Deleting Redundant Resources

After all persistent connections to the Nginx ingress are released and there is no more traffic being forwarded to it, you can safely release any unnecessary resources such as the Nginx ingress, NGINX ingress Controller, and webhook after observing for a period of time.