Forum Discussion

Andrew_Wysocki_'s avatar
Andrew_Wysocki_
Icon for Nimbostratus rankNimbostratus
Apr 15, 2016

GTM iRule to set the pool based on which GTM is responding to query

I've been asked that when a DNS request comes into a GTM, that it responds with the GTM pool which is local to that GTM site if it's available. The setup is as follows, 2 DC's, a GTM at each, synced together. We have a wide IP with 2 pools, in pool 1 it has servers based in DC1, and in pool 2, servers based in DC2. Currently we use Global Availability so only pool 1 is selected unless it's down. What was requested, if the DNS request ends up going to DC2 (understanding it's coming from the clients LDNS and not the client themselves), that the GTM at DC2 would respond with pool 2 instead of pool 1, as long as there's a server in it to respond.

I'm new to the coding of iRules, but wanted to take a shot at the logic, and hope someone with more experience can see if I'm on the right path, if there's a better way, or if there's error handling I should consider. I thought applying a GTM iRule to the wideIP is the best place to address this (as it's only relevant to the one site).

Looking at v10.New GTM irules it included the 'active_members' command, which I think is useful and is what I based my logic off of.

when DNS_REQUEST {
if { ([whoami] equals "dc-gtm01") && ( [active_members www.site1.com_pool1] >= 1) } {
    pool www.site1.com_pool1
    } elseif { [whoami] equals "dc-gtm02") && ( [active_members www.site1.com_pool2] >= 1 } {
        pool www.site1.com_pool2
    }
} 

So the theory is, if the request comes into gtm01, and pool 1 has an active member, it returns a member from that pool (don't care which one). If however it comes into gtm01, pool 1 is down, and the elseif doesn't match anything, will the iRule quit, and provide a pool 2 member as the returned value (assuming it's green)? This is the part I'm not sure of. Ultimately if both pools were down, the wideIP is down, so I shouldn't have to worry about that piece.

Same question/logic for gtm02, if the request comes in and pool 2 is down, would the iRule quit and end up selecting a member from pool 1?

Thanks in advance, Andrew

2 Replies

  • So think you will need something like the following.

    Your iRule using [whoami] returns the current user so need to use [hostname], this works on tclsh but not tested this directly on the iRule.

    when DNS_REQUEST {
      if { ([hostname] contains "dc-gtm01") && ( [active_members www.site1.com_pool1] >= 1) } {
           pool www.site1.com_pool1
        } elseif { [hostname] contains "dc-gtm02") && ( [active_members www.site1.com_pool2] >= 1 } {
            pool www.site1.com_pool2
        }
    } 
    
  • Hi think I understand what you are trying to do however can I ask how your DNS is setup to send traffic to your GTMs?

     

    Reason I ask is in most setups your GTMs will be Name Server (NS) records within some DNS and so requests from client will alternate between the GTMs and so if your iRule works as expected a client session (depending on the application) could flip between data centres.

     

    I would recommend looking at GTM Topology features which would allow you to set the DC based on the source IP/Subnet. i.e. Client sends query to local DNS which sends query to one of the GTMs, the GTM looks up the local DNS IP and selects the DC, pool or virtual server from the topology policies.