Forum Discussion

Sunnypro_250536's avatar
Sunnypro_250536
Icon for Nimbostratus rankNimbostratus
May 15, 2017

iRule for Load Balancing to Different Pools depending on the URI

Hello,

 

We need to have a Virtual Server to be configured on our LTM's which are running on the code version 10.2.4. we need to have two LTM ports configured that needs to load balance to 6 backend servers on different ports depending on the URI. So below is the way that we have the two LB URLS for port 443 and 7443 https://123.abc.com/def/ghi (for LTM port 443) https://123.abc.com:7443/def/ghi (for LTM port 7443)

 

And we have 6 servers on the backend having 7 ports each. server1 - 8100,8200,8300,8400,8500,8600,8700 server2 - 8100,8200,8300,8400,8500,8600,8700 server3 - 8100,8200,8300,8400,8500,8600,8700 server4 - 8100,8200,8300,8400,8500,8600,8700 server5 - 8100,8200,8300,8400,8500,8600,8700 server6 - 8100,8200,8300,8400,8500,8600,8700

 

And the URI's we have are

 

  1. For /account - it needs to load balance on port 8100 for all the 6 servers
  2. For /customer - it needs to load balance on port 8200 for all the 6 servers
  3. For /equipment - it needs to load balance on port 8300 for all 6 servers
  4. For /order - it needs to load balance on port 8400 for all the 6 servers
  5. For /statement - it needs to load balance on port 8500 for all the 6 servers
  6. For /payment - it needs to load balance on port 8600 for all 6 severs
  7. For /financials -it needs to load balance on port 8700 for all 6 servers.

So, here is the thing that it actually needs to work this way . Whenever if client hit the LB URL https://123.abc.com/def/ghi/account/ and if the LB URL has the /account it needs to load balance to all 6 servers on the port 8100 similarly if the LB URL is https://123.abc.com/def/ghi/customer/ it needs to load balance to all 6 servers on port 8200, for LB URL https://123.abc.com/def/ghi/equipment/ it needs to load balance to all 6 servers on port 8300 and for LB URL https://123.abc.com/def/ghi/order/ it needs to load balance to all 6 servers on port 8400 and for LB URL https://123.abc.com/def/ghi/statement/ it needs to load balance to all 6 servers on port 8500 and for the LB URL https://123.abc.com/def/ghi/payment/ it needs to load balance to all 6 servers on port 8600 and for the LB URL https://123.abc.com/def/ghi/financials/ it needs to load balance to all 6 server on port 8700.

 

The same needs to be working for the LTM port 7443, as these two LTM ports will be pointing to same VIP IP.

 

I know it can be configured with the iRule. Since I am not an expert in writing the iRules can anyone suggest me with the iRules that helps working the VIP as mentioned above. Also I wanted to know when we configure the VIP on 443 and 7443 do we need to attach an default pool for this or since we assign an iRule that would be enough for VIP to handle the traffic.

 

Please let me know your suggestions. Any help is greatly appreciated.

 

Thanks

 

  • Heya,

    You could use a policy for this but here is a quick iRule for you too (keep in mind you could also use a datagroup within the iRule).

    when HTTP_REQUEST {
    
    switch -glob [string tolower [HTTP::uri]] {
        "/def/ghi/account*" {
            pool  servers_8100
        }
        "/def/ghi/customer*" {
            pool servers_8200
        }
        "/def/ghi/equipment*" {
            pool servers_8300
        }
        "/def/ghi/order*" {
            pool servers_8400
        }
        "/def/ghi/statement*" {
            pool servers_8500
        }
        "/def/ghi/payment*" {
            pool servers_8600
        }
        "/def/ghi/financials*" {
            pool servers_8700
        }
        default {
            pool servers_default_pool
        }
    }
    }
    

    You could run the iRule/policy on both virtual servers (443/7443), just make sure any client/server ssl profiles are applied appropriately.

  • Anesh's avatar
    Anesh
    Icon for Cirrostratus rankCirrostratus
    • Below is an example use similar else if statements for the other pools and URI
    • Assign the iRule and not the pool
          when HTTP_REQUEST {
      if { ([HTTP::uri] starts_with "/def/ghi/account") } {
      pool 8100
      }elseif { [HTTP::uri] starts_with "/def/ghi/customer" } {
      pool 8200
      }elseif { [HTTP::uri] starts_with "/def/ghi/equipment" } {
      pool 8300
      }
      }
      
  • Heya,

    You could use a policy for this but here is a quick iRule for you too (keep in mind you could also use a datagroup within the iRule).

    when HTTP_REQUEST {
    
    switch -glob [string tolower [HTTP::uri]] {
        "/def/ghi/account*" {
            pool  servers_8100
        }
        "/def/ghi/customer*" {
            pool servers_8200
        }
        "/def/ghi/equipment*" {
            pool servers_8300
        }
        "/def/ghi/order*" {
            pool servers_8400
        }
        "/def/ghi/statement*" {
            pool servers_8500
        }
        "/def/ghi/payment*" {
            pool servers_8600
        }
        "/def/ghi/financials*" {
            pool servers_8700
        }
        default {
            pool servers_default_pool
        }
    }
    }
    

    You could run the iRule/policy on both virtual servers (443/7443), just make sure any client/server ssl profiles are applied appropriately.

    • Anesh's avatar
      Anesh
      Icon for Cirrostratus rankCirrostratus

      The above iRule is more optimized solution than mine, using a switch is better than elseif

       

  • Heya,

    You could use a policy for this but here is a quick iRule for you too (keep in mind you could also use a datagroup within the iRule).

    when HTTP_REQUEST {
    
    switch -glob [string tolower [HTTP::uri]] {
        "/def/ghi/account*" {
            pool  servers_8100
        }
        "/def/ghi/customer*" {
            pool servers_8200
        }
        "/def/ghi/equipment*" {
            pool servers_8300
        }
        "/def/ghi/order*" {
            pool servers_8400
        }
        "/def/ghi/statement*" {
            pool servers_8500
        }
        "/def/ghi/payment*" {
            pool servers_8600
        }
        "/def/ghi/financials*" {
            pool servers_8700
        }
        default {
            pool servers_default_pool
        }
    }
    }
    

    You could run the iRule/policy on both virtual servers (443/7443), just make sure any client/server ssl profiles are applied appropriately.

    • Anesh's avatar
      Anesh
      Icon for Cirrostratus rankCirrostratus

      The above iRule is more optimized solution than mine, using a switch is better than elseif