Docker to BIG-IP: Map container names to pool/node

Problem this snippet solves:

The associated iRule is used in the DevCentral article:

https://devcentral.f5.com/articles/connecting-docker-to-big-ip

This is a variation of https://devcentral.f5.com/articles/routing-http-by-request-headers

How to use this snippet:

Attach to virtual server. Expects two data groups exist: dg_docker_container and dg_docker_pool

Code :

when HTTP_REQUEST {
  set host_hdr [getfield [HTTP::host] ":" 1]
  set host_short [getfield $host_hdr "." 1]

  set node_addr [class match -value [string tolower $host_short] equals dg_docker_container]
  if { $node_addr ne "" } {
    node $node_addr
  } else {
    set pool_name [class match -value [string tolower $host_short] equals dg_docker_pool]
    if { $pool_name ne "" }
    {
      pool $pool_name
    } else {
    reject
    }
  }
}

Tested this on version:

11.5
Published Sep 01, 2015
Version 1.0
No CommentsBe the first to comment