HAproxy saves the day - overview of our built-in-two-days haproxy L4 load balancing system

This project was something I'd been wanting to do for quite some time, but never had the opportunity.  Well, opportunity kicked the door in, so who would I be to not offer tea & crumpets?

I've not had much exposure to load balancers so far aside from 'hey, they are neat' and understanding the basic concepts behind them.  Never had the chance to set one up from scratch, never done actual configuration, etc.  So why not have my first shot be with a pretty complex environment that had been badly maintained for the last 5 years? (they're dropping the contract at any moment, don't bother fixing it up - really)

We were moving said environment as a cost-savings exercise and had decided to forego load balancers (it was leaving behind some Stingray LBs) as another cost-saving exercise (we priced out Netscaler VMs at ~$2k each, Riverbed started at $5k).  Should be simple enough to just static-NAT straight to the servers and remove any redundancy (it was a dev environment, so should be fine) - right?

Well the day before we had that task to do I had to go and suggest that HAproxy should be something we use for our internal web stuff...and my co-worker got the bright idea to give HAproxy a shot for this environment.  Super!  (it was kinda exciting - and our boss had full confidence in us...so hey, why not)

I made the mistake of getting it running inside of two hours, fully redundant in another hour, and actively passing traffic in another hour.  It was decided!  HAproxy or death!

Then my co-worker made me aware of the minor details I'd overlooked when reviewing the Stingray config.  Persistence is not enough - what kind of persistence?  SSL front-end is not enough - what about back-end SSL? (yes this was a thing)  You get the idea.

Further, the way I'd set it up would work great in a 'normal' 443->80 scenario, but not so great with our multi-scenarios.  So then we got into ACLs, if statements, host header files...he laid out the logic, I modified the config, then we did the troubleshooting together.  It was super complicated, and my copy-pasta typos didn't help. (only 5 or 6 :) )

Our final 'done' config was over 500 lines...with 24 supplementary 'subdomain' files.  And we don't even use L7 load balancing...8 frontends, 24 backends, 6 SSL certs (wildcards).  The old LB uses 30+ public IPs for this environment - we are using 8.

It was a crazy couple of days, but we got it working, and I got a great trial-by-fire intro to the guts of load balancers.  I think the best lesson of this whole affair was to keep a really close track of what you're doing.  It is harder when you don't really grasp inner workings of load balancers, but still really valuable - not only for you, but for the next guy.

For example - my spreadsheet to track this looked like:

  • Public URL
  • Internal URL
  • Frontend Port
  • (Frontend Name)
  • SSL Decryption?
  • Old VIP
  • New VIP
  • Backend Port
  • Backend SSL?
  • SessionPersistence? (and what kind - ip or cookie)
  • Backend servers
  • Old BackendServer IPs
  • New BackendServer IPs
  • haproxyBackendName (We read that you should name these by 'where they are going': e.g. WEB12-https = WEB1 WEB2, https)

Some fun features:

  • Rsyslog output - sends to our ELK stack for easy log reading goodness (among other things)
  • Configuration is in Git (we manually deploy it...for now - don't want to install Git on the haproxy nodes however)
  • Keepalived for high availability - hosting 10 VIPs right now
  • check-mk-agent with haproxy plugin (each node outputs ~70 checks) from: https://github.com/hcooper/check_mk-plugins
  • The haproxy stats page is super-handy - I ended up binding this to a spare VIP so the config remains node-agnostic (not sure if this meets best practices)
  • We are also passing through SFTP (mode tcp, had to modify sshd_config)
And some stuff I still want to do:
  • haproxy - figure out how stuff like draining works
  • Build a proper (internet-safe) maintenance page
  • Packetbeat - not sure how it'll react to living on a load balancer
  • Chef - state/config management of the server
  • Add config pushing to our Thoughtworks Go system...overkill?  Or good practice?  :S
And I really need to read up on how to handle Linux servers with this kinda thing.  Weird, huh?  99% of my reading/research has been 'make Microsoft behave for Continuous Deployment'.  At least the Google fodder ratio is with me this time.


Popular posts from this blog

Learning through failure - a keyboard creation journey

Learning Opportunities - Watching/listening list

DFSR - eventid 4312 - replication just won't work