Help Center/ Elastic Load Balance/ Best Practices/ Using IP as a Backend to Route Traffic Across Backend Servers/ Routing Traffic to Backend Servers in the Same VPC as the Load Balancer
Updated on 2024-07-11 GMT+08:00

Routing Traffic to Backend Servers in the Same VPC as the Load Balancer

Scenarios

You can use ELB to route traffic to backend servers in the same VPC as the load balancer.

Solution

  • Dedicated load balancer ELB-Test is running in a VPC named vpc-peering (10.1.0.0/16).
  • An ECS named ECS-Test is also running in vpc-peering (10.1.0.0/16).
  • IP as a Backend is enabled for ELB-Test, and ECS-Test in vpc-peering (10.1.0.0/16) is added to the backend server group associated with ELB-Test in vpc-peering.
Figure 1 Topology

Advantages

You can enable IP as a Backend for a dedicated load balancer to route traffic to backend servers in the same VPC as the load balancer.

Resource and Cost Planning

The actual cost shown on the Huawei Cloud console is used.

Table 1 Resource planning

Resource Type

Resource Name

Description

Quantity

VPC

vpc-peering

The VPC where ELB-Test and ECS-Test are running:

10.1.0.0/16

1

VPC peering connection

Peering-Test

The connection that connects the VPC where ELB-Test is running and other VPCs.

Local VPC: 10.1.0.0/16

Peer VPC: any VPC

1

Route table

Route-VPC-Test-01

The route table of VPC-Test-01.

Destination: 10.1.0.0/16

1

ELB

ELB-Test

The dedicated load balancer to distribute incoming traffic.

Private IP address: 10.1.0.9

1

EIP

EIP-Test

The EIP bound to ELB-Test:

120.46.131.153

1

ECS

ECS-Test

The ECS that is running in vpc-peering.

Private IP address: 10.1.0.56

1

Operation Process

Figure 2 Process for adding backend servers in the same VPC as the load balancer

Step 1: Create a VPC

  1. Log in to the management console.
  2. Choose Networking > Virtual Private Cloud. On the displayed page, click Create VPC.
  3. Configure the parameters as follows and click Create Now. For details on how to create a VPC, see the Virtual Private Cloud User Guide.
    • Name: vpc-peering
    • IPv4 CIDR Block: 10.1.0.0/16
    • Configure other parameters as required.

Step 2: Create a VPC Peering Connection

  1. In the navigation pane on the left, click VPC Peering Connections.
  2. In the upper right corner, click Create VPC Peering Connection.
  3. Configure the parameters as follows and click Create Now. For details on how to create a VPC peering connection, see the Virtual Private Cloud User Guide.
    • Name: Peering-Test
    • Local VPC: vpc-peering
    • Peer VPC: any VPC
    • Configure other parameters as required.

Step 3: Add Routes for Peering-Test

  1. In the navigation pane on the left, click Route Tables.
  2. In the upper right corner, click Create Route Table.
  3. Configure the parameters as follows and click OK. For details on how to create a route table, see the Virtual Private Cloud User Guide.
    • Name: Route-VPC-Test-01
    • VPC: vpc-peering
    • Destination: 10.1.0.0/16
    • Next Hop Type: VPC peering connection
    • Next Hop: Peering-Test

Step 4: Create an ECS

  1. Under Compute, click Elastic Cloud Server.
  2. In the upper right corner, click Buy ECS.
  3. Configure the parameters as required. For details, see Elastic Cloud Server User Guide.

    Select vpc-peering as the VPC and set Name to ECS-Test.

  4. Deploy Nginx on the ECS-Test.
    Figure 3 Deploying Nginx on ECS-Test

Step 5: Create a Dedicated Load Balancer with an HTTP Listener and Associate a Backend Server Group

  1. On the management console, choose Networking > Elastic Load Balance.
  2. In the upper right corner, click Buy Elastic Load Balancer.
  3. Configure the parameters as follows. For details, see Elastic Load Balance User Guide.
    • Type: Dedicated
    • VPC: vpc-peering
    • Name: ELB-Test
    • IP as a Backend: Enable it.
    • Configure other parameters as required.
  4. Add an HTTP listener to ELB-Test and associate a backend server group with it.

Step 6: Add ECS-Test to the Backend Server Group

Locate ELB-Test and click its name.

  1. On the Default Backend Server Group area of the Summary tab, click View/Add Backend Server on the right.
  2. The page for adding backend servers is displayed.
  3. Click IP as Backend Servers on the lower part of the page. Click Add on the right, set parameters as required, and click OK. For details, see Elastic Load Balance User Guide.
    • IP Address: Set it to the private IP address of ECS-Test (10.1.0.56).
    • Backend Port: Set it as required.
    • Weight: Set it as required.

Step 7: Verify Traffic Routing

  1. Locate ELB-Test and click More in the Operation column.
  2. Select Bind IPv4 EIP to bind an EIP (120.46.131.153) to ELB-Test.
  3. Enter http://120.46.131.153/ in the address box of your browser to access ELB-Test. If the following page is displayed, ELB-Test routes the request to ECS-Test, which processes the request and returns the requested page.
    Figure 4 Verifying that the request is routed to ECS-Test