Especial Load Balancing Active-Passive Scenario (II)

Problem this snippet solves:

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

Topology:

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 <a_pool_name>] == 0 } {
        set selection "<b_pool_name>"
        table replace -subtable "[virtual name]" pool_selection $selection
    } elseif { [active_members <b_pool_name>] == 0 } {
        set selection "<a_pool_name>"
        table replace -subtable "[virtual name]" pool_selection $selection
    } elseif { [active_members <a_pool_name>] < 3 } {
        set selection "<b_pool_name>"
        table replace -subtable "[virtual name]" pool_selection $selection
    }
    # APPLY POOL SELECTION
    switch $selection {
        "<a_pool_name>" {
            pool <a_pool_name>
        }
        "<b_pool_name>" {
            pool <b_pool_name>
        }
        default {
            pool <a_pool_name>
            table set -subtable "[virtual name]" pool_selection <a_pool_name> indefinite indefinite
        }
    }
}</a_pool_name></a_pool_name></b_pool_name></b_pool_name></a_pool_name></a_pool_name></b_pool_name></a_pool_name></a_pool_name></b_pool_name></b_pool_name></a_pool_name>

Tested this on version:

12.1

Hello.

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