Use GTM and CLB instances to implement cross-region load balancing

Updated at:
Copy as MD

When services in one region fail, Global Traffic Manager (GTM) detects the failure through health checks and automatically reroutes DNS traffic to a healthy region—keeping your service online without manual intervention. This tutorial shows you how to pair GTM with Classic Load Balancer (CLB) instances in two regions to build a cross-region active-passive architecture.

How it works

GTM operates at the DNS layer. It monitors the health of your CLB instances in each region and responds to DNS queries with the IP address of a healthy endpoint. When a regional failure is detected, GTM stops returning that region's IP address and directs all traffic to the other region.

GTM can manage IP addresses from Alibaba Cloud and other service providers, enabling hybrid cloud deployments.

Cross-region load balancing architecture diagram

In this tutorial, Elastic Compute Service (ECS) instances run behind CLB instances in two regions—China (Hangzhou) and China (Beijing). GTM is configured to route traffic to both regions under normal conditions and to fail over to the surviving region when one becomes unavailable.

For more information about GTM, see What is Global Traffic Manager?.

Prerequisites

Before you begin, make sure you have:

Step 1: Purchase a GTM instance

  1. Log in to the Alibaba Cloud DNS console.

  2. In the left-side navigation pane, click Global Traffic Manager.

  3. Click Purchase Instance.

  4. On the purchase page, configure the parameters and complete the payment. The default settings are used in this tutorial.

Step 2: Configure GTM

Configure the GTM instance

  1. On the Global Traffic Manager page, click the ID of the GTM instance, or click Settings in the Actions column.

  2. If this is your first time configuring GTM, select Advanced Settings in the Select Configuration Method dialog box.

  3. On the Basic Settings tab, click Modify. In the Modify Basic Settings panel, configure the following parameters and click OK.

    Setting

    Value

    CNAME (Internet)

    Select Custom Access Domain Name. Enter the prefix and suffix of your domain name. After you save the settings, a CNAME record is automatically generated that maps your domain to the GTM instance.

    Global TTL Period

    Set the duration that DNS resolvers cache the IP address.

    Alert Group

    Select a contact group to receive notifications when an endpoint becomes unhealthy. The CloudMonitor alert group appears in the list by default. See Create an alert contact or alert contact group.

Configure address pools

Each CLB instance must be placed in a separate address pool. This tutorial uses two address pools—one for each CLB instance.

Do not add both CLB instances to the same address pool. GTM requires each CLB public IP address to be in a different pool to route traffic independently.
  1. On the Address Pools tab, click Create Address Pool.

  2. In the Create Address Pool panel, set the Address parameter in the Addresses list to the public IP address of one of your CLB instances. Configure other parameters or use the default values, then click OK.

  3. Repeat the preceding steps to create a second address pool with the public IP address of the other CLB instance.

Configure health checks

Configure a health check for each address pool so that GTM can detect regional failures.

  1. On the Address Pools tab, find an address pool and click the Expand icon to expand its configuration.

  2. Click Add next to Health Check. In the Modify Health Check Settings panel, set the health check protocol and port to match the backend protocol and port of your CLB listener. Configure the remaining parameters or use the default values, then click OK.

  3. Repeat the preceding steps to configure a health check for the other address pool.

Configure an access policy

  1. On the Basic Settings tab, go to the Access Policy Type section and click Settings in the Geographical Location-based Access Policy card.

  2. On the Geographical Location-based Access Policy page, click Create Access Policy.

  3. In the Create Access Policy panel, configure the following parameters and click OK.

    Setting

    Value

    DNS Request Source

    Select Global to route traffic from different regions or Internet service providers (ISPs) to the address pools.

    Primary Address Pool Set

    Select the address pools in all regions.

Step 3: Verify the result

Verify both normal operation and failover behavior.

Test normal operation:

  1. Open a browser and access your service using the CNAME generated in Step 2.

  2. Confirm that the service loads successfully.

Test failover:

  1. Disable the backend services in one of the regions to simulate a fault.

  2. Wait a few seconds for the health check to detect the failure, then refresh the page.

  3. Confirm that the service is still accessible—traffic has been rerouted to the other region.

To view detailed failover logs, go to the Alert Logs tab of your GTM instance.

What's next

Application Load Balancer (ALB) and Network Load Balancer (NLB) also support cross-region architectures. Choose the load balancer type that fits your protocol and traffic requirements: