Help Center> Elastic Load Balance> Best Practices> Routing Traffic to Backend Servers in Different VPCs> Routing Traffic to Backend Servers in the Same VPC as the Load Balancer
Updated on 2023-10-09 GMT+08:00

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

Scenarios

You can route traffic to backend servers in the VPC where the load balancer is running.

Solution

  • A dedicated load balancer ELB-Test is running in a VPC named vpc-peering (10.1.0.0/16).
  • The backend server ECS-Test is also running in vpc-peering (10.1.0.0/16).
  • ECS-Test needs to be added to the backend server group associated with ELB-Test.
Figure 1 Adding a backend server in the same VPC as the load balancer

Advantages

You can add servers in the same VPC as the load balancer to the backend server group of the load balancer and then route incoming traffic to the servers.

Resource and Cost Planning

The estimated cost (CNY 782.78) provided in this document is for reference only. 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 named ELB-Test

Private IP address: 10.1.0.9

1

EIP

EIP-Test

The EIP (120.46.131.153) bound to ELB-Test

120.46.131.153

1

ECS

ECS-Test

The ECS works 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

Creating a VPC

  1. Log in to the management console.
  2. Under Networking, select Virtual Private Cloud. On the Virtual Private Cloud page displayed, 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.
    Figure 3 Creating vpc-peering

Creating a VPC Peering Connection

  1. In the navigation pane on the left, click VPC Peering.
  2. In the upper right corner, click Create VPC Peering Connection.
  3. Configure the parameters as follows and click OK. 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.
    Figure 4 Creating Peering-Test

Adding Routes for the VPC Peering Connection

  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
    Figure 5 Creating Route-VPC-Test-01

Creating an ECS

  1. Under Computing, 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 for VPC and set Name to ECS-Test.

    Figure 6 Buying ECS-Test

  4. Deploy Nginx on the ECS.

    Figure 7 Deploying Nginx on ECS-Test

Buying a Dedicated Load Balancer and Adding an HTTP Listener and a Backend Server Group to the Load Balancer

  1. Under Networking, click 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
    • IP as a Backend: Enable
    • VPC: vpc-peering
    • Name: ELB-Test
    • Configure other parameters as required.
    Figure 8 Creating a dedicated load balancer named ELB-Test

  4. Add an HTTP listener and a backend server group to the created dedicated load balancer. For details, see Elastic Load Balance User Guide.

Adding the ECS to the Backend Server Group

  1. Locate the dedicated load balancer and click its name ELB-Test.
  2. On the Listeners tab page, locate the HTTP listener added to the dedicated load balancer and click its name.
  3. In the Backend Server Groups tab on the right, click IP as Backend Servers.
  4. Click Add IP as Backend Server, configure the parameters, and click OK. For details, see Elastic Load Balance User Guide.

    • Backend Server IP Address: 10.1.0.56 (private IP address of ECS-Test)
    • Backend Port: the port enabled for Nginx on ECS-Test
    • Weight: Configure this parameter as required.
    Figure 9 Adding IP as backend servers

Verifying Traffic Routing

  1. Locate the dedicated load balancer 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.

    Figure 10 EIP bound to the load balancer

  3. Enter http://120.46.131.153/ in the address box of your browser to access the dedicated load balancer. If the following page is displayed, the load balancer routes the request to ECS-Test. After receiving the request from the load balancer, ECS-Test processes the request and returns the requested page.

    Figure 11 Verifying traffic routing