Forum Discussion

B_Biggs's avatar
B_Biggs
Icon for Nimbostratus rankNimbostratus
Jan 13, 2025

iRule to Change Default Pool (not redirect to another pool)?

Everyone,

    Moving from NetScaler to BigIP, LTM, and F5 and am "drinking from the firehose" trying to learn everything I can before my company goes live. I could use some suggestions here so here it goes:

Scenario:

My company has a blue/green deployment model. I'm looking to use the LTM to direct traffic to the application to the proper pools/nodes based on a STATIC variable set with a RULE_INIT event. All developers have to do in their deployment pipeline is send an API call to BigIP to change the variable to blue/green as needed. We have opted for this design because if changes need to be made within F5 for any reason (object renaming, partition changing, etc.), developers don't have to change their pipelines to accommodate. The application has an iRule which then reads the variable value and directs to proper pool using SWITCH.  Simple.

 

Challenge:

Because the iRule is technically looking at two pools in its logic, when I disable the nodes in the "active" pool, if the "inactive" pool is still up, LTM leaves the Virtual Server as up/green, even though traffic cannot reach the disabled "active" nodes on the server side (should register as "grey" in my test).

 

Solution(?):

Rather than recreate the monitoring logic in the iRule for the site (and multiple other future sites), I would think the easiest way to leverage existing LTM architecture would be to change the logic of the iRule to change the Default Pool of the application when the STATIC variable changes. Is it possible to do this within an iRule? Every time I search for this option, I only get hits on how to redirect to different pools.

Or perhaps there is another way to accomplish this that I am not aware of? Any input would be appreciated. Thanks!

  • Hi

    its posible, you can used a police rule or iRule.

    You can make a iRule to identify a header and divert traffic from poolA to poolB.

     

     

    If you need help with that, let me know with, we are the best community šŸ˜

     

    • B_Biggs's avatar
      B_Biggs
      Icon for Nimbostratus rankNimbostratus

      JoseLabra,

      Thank you for your quick reply. However, your proposed solution does not address my scenario. If you could read through my post and provide your thoughts, it would be appreciated. Thanks!

  • f51's avatar
    f51
    Icon for Cirrocumulus rankCirrocumulus

    Hi there! Transitioning from NetScaler to F5's Big-IP LTM can indeed feel like drinking from a firehose, but I will try to help! Your scenario is quite common in environments with blue/green deployments, and you've outlined a clear strategy for handling dynamic traffic routing using iRules.

    For your specific challenge, you want to dynamically change the default pool based on a STATIC variable while maintaining the existing LTM monitoring. Unfortunately, directly changing the default pool of a Virtual Server via an iRule is not supported because iRules are designed to handle traffic flow rather than configuration changes.

    However, you can achieve your goal by employing a combination of iRules and LTM features. Below are a couple of approaches to consider:

    Approach 1: Using iRule with Pool Selection Logic

    Instead of changing the default pool, you can use an iRule to dynamically select the pool based on the value of your STATIC variable. Here's an example of how you might write such an iRule:

    when RULE_INIT {
        set static::deployment "blue"  ;# Initialize with default value
    }

    when HTTP_REQUEST {
        switch -exact [static::deployment] {
            "blue" {
                pool pool_blue
            }
            "green" {
                pool pool_green
            }
            default {
                reject
            }
        }
    }

    In this example, the iRule directs traffic to pool_blue or pool_green based on the value of static::deployment. You can update the STATIC variable using an API call to Big-IP, which should update the variable without requiring developers to change their pipelines.

    Approach 2: Using a Data Group and iRule

    Another method is to use a Data Group to store the current deployment status and reference it within your iRule. Hereā€™s how you can do it:

    1. Create a Data Group (e.g., deployment_status) with an entry like current_deployment := blue.
    2. Update the Data Group using an API call when you switch deployments.
    3. Reference the Data Group in your iRule to direct traffic accordingly.

    when HTTP_REQUEST {
        set deployment_status [class lookup current_deployment deployment_status]
        switch -exact $deployment_status {
            "blue" {
                pool pool_blue
            }
            "green" {
                pool pool_green
            }
            default {
                reject
            }
        }
    }

    Monitoring and Failover

    To handle the monitoring aspect, ensure that each pool has appropriate health monitors configured. This way, if all nodes in the active pool go down, the LTM can automatically fail over to the backup pool based on the health monitor status.

    In summary, while you can't change the default pool directly via an iRule, you can use iRules to dynamically select the appropriate pool based on a variable. Additionally, using Data Groups can provide a more structured and easily manageable approach to store and update deployment status.

    I hope this helps! If you have any further questions or need additional clarification, feel free to ask.