Updated on 2023-12-18 GMT+08:00

Adding a Forwarding Policy

API Format

Method

URI

Description

POST

/v2.0/lbaas/l7policies

Adds a forwarding policy.

Application Scenarios

By adding forwarding policies and rules, you can forward different requests to a specific backend server.

Suppose that you have several servers on the cloud platform to provide services for the Internet, and the resources mainly include music (/music/{music_id}), images (/pic/{pic_id}), and files (/file/{file_id}). If there are no forwarding policies, each backend server has a copy of all resources. Requests from a client are always distributed to only one backend server. Therefore, only one copy is used. The storage cost increases as there are more and more backend servers.

Forwarding policies and rules provided by ELB can well solve this problem. In this way, the storage cost is reduced and you can obtain better economic benefits.

Constraints

  • Forwarding policies can be added for listeners when protocol is set to HTTP or TERMINATED_HTTPS.
  • The value of redirect_pool configured for the forwarding policy cannot be the same as that of default_pool configured for the listener.
  • The backend server group specified in redirect_pool cannot be used by forwarding policies of other listeners.

Scenario Assumption

Assume that you have created a load balancer named loadbalancer_1. You can add a listener named listener_1 and three backend server groups pool_1, pool_2, and pool_3. pool_1 is the default backend server group of listener_1, and pool_2 and pool_3 are associated with loadbalancer_1. For better load distribution, HTTP requests whose URI starts with /music are sent to pool_2, and HTTP requests whose URI starts with /pic are forwarded to pool_3.

Procedure

To match the URIs, HTTP messages need to be parsed. Therefore, the listener and three backend server groups must use the HTTP or HTTPS protocol.

  1. Add an HTTP listener named listener_1.

    POST https://elb.cn-east-2.myhuaweicloud.com/v2.0/lbaas/listeners
    {
        "listener": {
            "protocol_port": "80",
            "protocol": "HTTP",
            "loadbalancer_id": "abe3ee34-1882-408f-a2ba-1ce7e428d6e3",
            "name": "listener_1",
            "admin_state_up": true
        }
    }

  2. Add a backend server group named pool_1 and its backend protocol is HTTP.

    POST https://elb.cn-east-2.myhuaweicloud.com/v2.0/lbaas/pools/
    { 
      "pool": { 
      "name":"pool_1",
        "lb_algorithm": "ROUND_ROBIN", 
        "listener_id": "a7b996cf-23ec-4c0b-b310-45495d29f80c", 
        "protocol": "HTTP", 
        "admin_state_up": true 
      } 
    }

  3. Add a backend server group named pool_2 and its backend protocol is HTTP.

    POST https://elb.cn-east-2.myhuaweicloud.com/v2.0/lbaas/pools/
    { 
      "pool": { 
      "name":"pool_2",
        "lb_algorithm": "ROUND_ROBIN", 
        "listener_id": "a7b996cf-23ec-4c0b-b310-45495d29f80c", 
        "protocol": "HTTP", 
        "admin_state_up": true 
      } 
    }

  4. Add a backend server group named pool_3 and its backend protocol is HTTP.

    POST https://elb.cn-east-2.myhuaweicloud.com/v2.0/lbaas/pools/
    { 
      "pool": { 
      "name":"pool_3",
        "lb_algorithm": "ROUND_ROBIN", 
        "listener_id": "a7b996cf-23ec-4c0b-b310-45495d29f80c", 
        "protocol": "HTTP", 
        "admin_state_up": true 
      } 
    }

  5. Add a forwarding policy to pool_2.

    POST https://elb.cn-east-2.myhuaweicloud.com/v2.0/lbaas/l7policies
    { 
        "l7policy": { 
            "action": "REDIRECT_TO_POOL",  
            "listener_id": "a7b996cf-23ec-4c0b-b310-45495d29f80c",  
            "redirect_pool_id": "b9a01911-8364-44d8-ab5a-4f635820edb2",  
            "name": "l7policy_music",  
            "admin_state_up": true 
        } 
    }

  6. Add a forwarding policy to pool_3.

    POST https://elb.cn-east-2.myhuaweicloud.com/v2.0/lbaas/l7policies
    { 
        "l7policy": { 
            "action": "REDIRECT_TO_POOL",  
            "listener_id": "a7b996cf-23ec-4c0b-b310-45495d29f80c",  
            "redirect_pool_id": "3a9b8338-3086-4acc-92e6-83c5e750e44a",  
            "name": "l7policy_pic",  
            "admin_state_up": true 
        } 
    }

  7. Check the created forwarding policies. They do not match any request because there are no specific forwarding rules. To make the forwarding policies to take effect, forwarding rules must be added to forward requests with different URIs.