cancel
Showing results for 
Search instead for 
Did you mean: 

Problem this snippet solves:

I share with you one special load balancing scenario that I had to deal with.


Topology:


0151T000003kQZEQA2.png


Requirements:


  • There are two pools configured (Pool_A & Pool_B)
  • The members of each pool will work using Round Robin LB method.
  • One pool will act as active and the other one will be in standby mode.
  • Only the pool with active role will be able to process traffic.
  • If 2 or more members of Pool_A (initially active) are down, Pool_B (initially standby) asumes the role of active.
  • There is no preempt, in case of Pool_B asumes the active role, it will be active until someone decide to roll back to the initial situation (manually).


How to use this snippet:

It's easy to configure. You need to configure a virtual server without default pool and this iRule applied to it.


Considerations:


  • The iRule uses a table variable to keep the state of the current active pool.
  • The code will use Pool_A as active pool in the first execution.
  • You can manually force an active pool disabling the other pool.
  • In case you would like to remove this VS indefinitely, you should manually remove the table variable.


Remove Table Variable:


For deleting the table variable you can replace the irule for this one and execute it once.


when CLIENT_ACCEPTED {
  table delete -all -subtable "[virtual name]"
  log local0. "[virtual name] table was deleted"
}


You can also define a timeout value for the variable instead of using indefinite.

REF - https://devcentral.f5.com/s/articles/v101-the-table-command-advanced-data-expiration


Code :

when CLIENT_ACCEPTED {
    # PICK THE LAST POOL SELECTION
    set selection [table lookup -subtable "[virtual name]" pool_selection]
    # EVAL POOL SELECTION
    if { [active_members ] == 0 } {
        set selection ""
        table replace -subtable "[virtual name]" pool_selection $selection
    } elseif { [active_members ] == 0 } {
        set selection ""
        table replace -subtable "[virtual name]" pool_selection $selection
    } elseif { [active_members ] < 3 } {
        set selection ""
        table replace -subtable "[virtual name]" pool_selection $selection
    }
    # APPLY POOL SELECTION
    switch $selection {
        "" {
            pool 
        }
        "" {
            pool 
        }
        default {
            pool 
            table set -subtable "[virtual name]" pool_selection  indefinite indefinite
        }
    }
}

Tested this on version:

12.1
Comments

Hello.

I've noticed the code is not correct. There is some info missed. You can use this link instead.

https://github.com/DariuSGB/F5_iRules/blob/master/LB_2Pools.tcl

Version history
Last update:
‎21-Jun-2019 08:12
Updated by:
Contributors