This topic describes how to add Elastic Compute Service (ECS) instances in a virtual private cloud (VPC) to an Application Load Balancer (ALB) instance in a different region. To add ECS instances in a VPC to an ALB instance in a different region, you must use transit routers of Cloud Enterprise Network (CEN). Transit routers are used to route network traffic from the ALB instance to the ECS instances.

Scenario

The example in this topic is based on the following scenario. A company created a VPC (VPC1) in the China (Chengdu) region and deployed an ALB instance in VPC1. The company created a VPC (VPC2) in the China (Hangzhou) region and created ECS instances in VPC2. The company wants to add the ECS instances in VPC2 to the ALB instance in VPC1.

To achieve this goal, the company uses a CEN instance and attaches both VPCs to it. This effectively allows the ECS instances in VPC2 to function as the backend servers of the ALB instance in VPC1.

Scenario: Add ECS instances to an ALB instance in a different region

Precautions

  • If you want to add ECS instances to an ALB instance in a different region, you must first add the ECS instances to a server group of the IP type.
  • The following table lists the regions where you can specify ECS instances in another region as backend servers of ALB.
    AreaRegion
    ChinaChina (Chengdu), China (Qingdao), China (Beijing), China (Guangzhou), China (Hangzhou), China (Ulanqab), China (Shanghai), China (Shenzhen), China (Zhangjiakou), and China (Hong Kong)
    Asia PacificIndonesia (Jakarta), Japan (Tokyo), Malaysia (Kuala Lumpur), Australia (Sydney), Singapore, and India (Mumbai)
    Europe and AmericasGermany (Frankfurt), UK (London), US (Virginia), and US (Silicon Valley)
  • VPC1 and VPC2 must be attached to the same CEN instance.
  • When you associate Enterprise Edition transit routers with the VPCs, elastic network interfaces (ENIs) are automatically created. Then, the ENIs are attached to the vSwitch in each zone. The ENIs are used to forward network traffic from the VPCs to the Enterprise Edition transit routers. When you create the VPCs, you must specify at least one vSwitch in each zone of the Enterprise Edition transit routers. This way, network traffic can be routed from the VPCs to the transit routers. For more information, see Regions and zones that support Enterprise Edition transit routers.
  • You can add only internal-facing servers and cannot add Internet-facing servers.
  • You cannot add ALB or CLB instances that reside in the same VPC.
  • Enterprise edition transit routers support cross-region data forwarding. Basic edition transit routers do not support cross-region data forwarding.
  • Each region in a network managed by a CEN instance can have only one VPC in which one or more ALB instances can add backend servers across regions. Example 1 of adding ECS instances across VPCs
    • You cannot enable ALB instances in multiple VPCs in the same region to use the same transit router to access backend servers in the VPCs across regions. Example 2 of adding ECS instances across VPCs
    • You cannot enable ALB instances in multiple VPCs in the same region to use multiple transit routers to access backend servers in the same VPC across regions. Example 3 of adding ECS instances across VPCs
  • Network traffic between an ALB instance and its backend servers can be routed based only on the system route table. VPC custom route tables are not supported.

Prerequisites

  • A VPC (VPC1) is created in the China (Chengdu) region. Another VPC (VPC2) is created in the China (Hangzhou) region.
    • Two vSwitches (VSW1 and VSW2) are created in VPC1. VSW1 is deployed in Zone A and VSW2 is deployed in Zone B.
    • Two vSwitches (VSW3 and VSW4) are created in VPC2. VSW3 is deployed in Zone H and VSW4 is deployed in Zone I.
    For more information, see Create and manage a VPC.
  • ECS instances are created in VPC1 to send connection requests. An ECS instance named ECS1 is created in VPC2 and an application is deployed on ECS1 to receive connection requests. For more information, see Create an instance by using the wizard.
  • An ALB instance is created in VPC1. For more information, see Create an ALB instance.
  • A CEN instance is created and a bandwidth plan is associated with the CEN instance. For more information, see Create a CEN instance and Work with a bandwidth plan.
  • A transit router is deployed in the China (Chengdu) region. Another transit router is deployed in the China (Hangzhou) region. For more information, see Create a transit router.

The following table describes how networks are planned. You can plan the CIDR blocks based on your business requirements. Make sure that the CIDR blocks do not overlap with each other.

RegionVPCvSwitch ZoneCIDR block
China (Chengdu)VPC1

Primary CIDR block: 172.16.0.0/12

VSW1Zone A172.16.0.0/24
VSW2Zone B172.16.6.0/24
China (Hangzhou)VPC2

Primary CIDR block: 192.168.0.0/16

VSW3Zone H192.168.8.0/24
VSW4Zone I192.168.7.0/24

Procedure

Procedure for adding backend servers to an ALB instance in a different region

Step 1: Create a server group for the ALB instance

Create a server group of the IP type. Then, add the IP addresses of the ECS instances that you want to specify as backend servers to the server group.

  1. Log on to the ALB console.
  2. In the top navigation bar, select the region where the ALB instance is deployed. In this example, China (Chengdu) is selected.
  3. In the left-side navigation pane, choose ALB > Server Groups.
  4. On the Server Groups page, click Create Server Group, set the following parameters, and then click Create.
    ParameterDescription
    Server Group TypeSelect the type of server group that you want to create. In this example, IP is selected.
    Server Group NameEnter a name for the server group.
    VPCSelect a VPC from the drop-down list. In this example, VPC1 is selected.
    Backend Server ProtocolSelect a backend protocol. HTTP is selected in this example.
    Scheduling AlgorithmSelect a scheduling algorithm. In this example, the default value Weighted Round-robin is used.
    Resource GroupSelect the resource group to which the server group belongs.
    Session PersistenceSpecify whether to enable or disable session persistence. In this example, session persistence is disabled.
    Configure Health CheckSpecify whether to enable the health check feature. In this example, health checks are enabled.
    Advanced SettingsIn this example, the default advanced settings are used. For more information, see Create and manage a server group.
  5. On the Server Groups page, find the server group that you want to manage and click Modify Backend Server in the Actions column.
  6. On the Backend Servers tab, click Add IP Address.
  7. In the Add Backend Server panel, enter the private IP address of ECS1, turn on Remote IP Address, and then click Next.
  8. Specify the port and weight of the IP address and click OK. In this example, the port is set to 80 and the default weight is used.

Step 2: Configure a listener for the ALB instance

  1. Log on to the ALB console.
  2. In the top navigation bar, select the region where the ALB instance is deployed. In this example, China (Chengdu) is selected.
  3. On the Instances page, find the ALB instance that is deployed in VPC1 and click Create Listener in the Actions column.
  4. In the Configure Listener step, set the following parameters and click Next.
    ParameterDescription
    Listener ProtocolSelect a listening protocol. HTTP is selected in this example.
    Listener PortSpecify the port on which the ALB instance listens. The ALB instance listens for requests on the specified port and then forwards the requests to backend servers. Valid values: 1 to 65535. In this example, 80 is specified.
    Listener NameSpecify a name for the listener.
    Advanced SettingsIn this example, the default advanced settings are used.
  5. On the Select Server Group wizard page, select IP from the Server Group drop-down list, select the server group created in Step 1, and then click Next.
  6. On the Confirm wizard page, confirm the configurations and click Submit.

Step 3: Attach the VPCs to the CEN instance

  1. Log on to the CEN console.
  2. On the Instances page of the CEN console, click the ID of the CEN instance that you want to manage.
  3. On the Basic Settings > Transit Router tab, find the transit router that you want to manage and click Create Connection in the Actions column.
  4. On the Connection with Peer Network Instance page, set the following parameters and click OK.
    ParameterDescription
    Network TypeIn this example, VPC is selected.
    RegionSelect the region where the network instance is created. In this example, China (Chengdu) is selected.
    Transit RouterThe transit router in the selected region is selected by default.
    Resource Owner ID

    Specify whether the network instance belongs to the current or another account. In this example, Your Account is selected.

    Billing MethodIn this example, Pay-As-You-Go is selected.
    Attachment NameEnter a name for the connection.
    Network InstanceSelect the ID of the VPC that you want to connect. In this example, VPC1 is selected.
    VSwitchSelect vSwitches that are deployed in zones supported by Enterprise Edition transit routers. In this example, VSW1 and VSW2 are selected.
    Advanced Settings

    The advanced features are selected by default. In this example, the default advanced settings are used.

  5. After you attach VPC1 to the CEN instance, click Create More Connections and repeat Substep 4 of Step 3: Attach the VPCs to the CEN instance to attach VPC2 to the CEN instance.
    In this example, the following configurations are used. The default settings are kept for parameters that are not described in this section.
    • Region is set to China (Hangzhou).
    • VPC2 is selected for Networks.
    • VSwitch is set to VSW3 in Hangzhou Zone H and VSW4 in Hangzhou Zone I.

Step 4: Create an inter-region connection

  1. Log on to the CEN console.
  2. On the Instances page, click the ID of the CEN instance that you want to manage.
  3. On the Basic Settings > Transit Router tab, find the transit router that you want to manage and click Create Connection in the Actions column.
    You can choose the transit router that is associated with VPC1 or the transit router that is associated with VPC2. In this example, the transit router associated with VPC1 is used.
  4. On the Connection with Peer Network Instance page, set the following parameters and click OK.
    ParameterDescription
    Network TypeSelect Inter-region Connection.
    RegionSelect one of the regions to be connected. In this example, China (Chengdu) is selected.
    Transit RouterSelect the transit router deployed in the selected region.
    Attachment NameSpecify a name for the inter-region connection.
    Peer RegionSelect the other region to be connected. China (Hangzhou) is selected in this example.
    Bandwidth Allocation ModeIn this example, Allocate from Bandwidth Plan is selected.
    Bandwidth PlanSelect a bandwidth plan that is associated with the CEN instance.
    BandwidthSpecify a valid bandwidth value. Unit: Mbit/s.
    Advanced SettingsIn this example, the default advanced settings are used.

Step 5: Add routes to the system route table of VPC1

Check whether the system route table of VPC1 contains a route that points to the VPC1 connection. If no routes point to the VPC1 connection, perform the following operations to add a route that points to the VPC1 connection:
Note Network traffic between an ALB instance and its backend servers can be routed based only on the system route table. VPC custom route tables are not supported.
  1. Log on to the VPC console.
  2. On the VPCs page, click the ID of VPC1.
  3. On the details page, click the Resources tab and then click the number below Route Table.
  4. On the Route Tables page, find the route table whose Route Table Type is System and click its ID.
  5. On the details page of the route table, choose Route Entry List > Custom Route, and click Add Route Entry.
  6. In the Add Route Entry panel, set the following parameters and click OK.
    ParameterDescription
    NameEnter a name for the route.
    Destination CIDR BlockEnter the CIDR block that you want to access. In this example, the CIDR block of ECS1 is entered, which is 192.168.7.0/24.
    Next Hop TypeSelect the type of the next hop. Transit Router is selected in this example.
    Transit RouterSelect a transit router. In this example, the VPC1 connection is selected.

Step 6: Configure back-to-origin routes

View the back-to-origin route of the ALB instance. Add the back-to-origin route to the system route table of VPC2 and the route table of the transit router that is associated with VPC1.

  1. Perform the following operations to view the back-to-origin route of an ALB instance:
    1. Log on to the ALB console.
    2. In the top navigation bar, select the region where the ALB instance is deployed. In this example, China (Chengdu) is selected.
    3. On the Instances page, click the ID of the ALB instance in VPC1.
    4. On the Instance Details tab, click View next to Back-to-origin Route.
  2. Perform the following operations to add the back-to-origin route of ALB to the system route table of VPC2:
    1. Log on to the VPC console.
    2. On the VPCs page, click the ID of VPC2.
    3. On the details page, click the Resources tab and then click the number below Route Table.
    4. On the Route Tables page, find the route table whose Route Table Type is System and click its ID.
    5. On the Route Entry List > Custom Route tab, click Add Route Entry.
    6. In the Add Route Entry panel, set the following parameters and click OK.
      ParameterDescription
      NameEnter a name for the route.
      Destination CIDR BlockEnter the CIDR block that you want to access. In this example, the destination CIDR block of the back-to-origin route of the ALB instance is entered, which is obtained from Substep 1 of Step 6. If the ALB instance has multiple back-to-origin routes, repeat the preceding operations to add all of the back-to-origin routes.
      In this example, the following routes are configured for VPC2:
      • 100.XX.XX.0/25
      • 100.XX.XX.128/25
      • 100.XX.XX.64/26
      • 100.XX.XX.128/26
      • 100.XX.XX.192/26
      • 100.XX.XX.0/26
      Next Hop TypeSelect the type of the next hop. Transit Router is selected in this example.
      Transit RouterSelect a transit router. In this example, the transit router that is associated with VPC2 is selected.
  3. Perform the following operations to add the back-to-origin route of ALB to the transit router associated with VPC1:
    1. Log on to the CEN console.
    2. On the Instances page, click the ID of the CEN instance that you want to manage.
    3. Choose Basic Settings > Transit Router, find the transit router associated with VPC1, and then click its ID.
    4. On the Route Table tab, click the ID of the route table to which you want to add the back-to-origin route, click the Route Entry tab, and then click Add Route Entry.
    5. In the Add Route Entry dialog box, set the following parameters and click OK.
      ParameterDescription
      Route TableThe current route table is selected by default.
      Transit RouterThe current transit router is selected by default.
      NameEnter a name for the route.
      Destination CIDREnter the destination CIDR block of the route. In this example, the destination CIDR block of the back-to-origin route of the ALB instance is entered, which is obtained from Substep 1 of Step 6. If the ALB instance has multiple back-to-origin routes, repeat the preceding operations to add all of the back-to-origin routes.
      In this example, the following routes are configured for the transit router associated with VPC1:
      • 100.XX.XX.0/25
      • 100.XX.XX.128/25
      • 100.XX.XX.64/26
      • 100.XX.XX.128/26
      • 100.XX.XX.192/26
      • 100.XX.XX.0/26
      Blackhole RouteThe default value No is selected.
      Next HopSelect a next hop. In this example, the VPC1 connection is selected.
      DescriptionEnter a description for the route.

Step 7: Check the security group rules of the ECS instances

Packets are sent from the CIDR block of the back-to-origin route to the ECS instances. Make sure that the security group rules of the ECS instances allow access from the CIDR block. In the example in this topic, you need to add inbound rules to the security group of the ECS instance to allow access from the back-to-origin CIDR block (100.64.0.0/10) of ALB. Otherwise, the access to backend services across regions fails. For more information, see Add a security group rule

Step 8: Test network connectivity

  1. Log on to the ECS instance that is deployed in VPC1. For more information, see Guidelines on ECS instance connection.
  2. Run the wget http://domain name of the ALB instance command to check whether the ECS instance in VPC1 can access ECS1 in VPC2 through the ALB instance.
    You can view the domain name of the ALB instance on the details page of the ALB instance.
    The command used in this example is:
    wget http://alb-fo89znps6q********.internal.cn-chengdu.alb.aliyuncs.com
    If you can receive echo reply packets, the connection is established, as shown in the following figure. Connectivity test