Dynamic NGINX Upstreams from Consul via lua-nginx-module.
3 min readMay 11, 2016
Recently I delivered a short talk at DevOps Days Austin contrasting the difference between hacking and engineering utilizing the problem of resolving NGINX upstreams dynamically from Consul. This article presents the technical solution sparing you the rhetoric. Those interested may review the slides from the talk here: Hacking vs Engineering.
REQUIREMENTS
- Must be able to present various service functionality via a single hostname to the user
- Must be able to expand backend service capacity without running configuration management on load balancers
- Must resolve backend services for associated URI paths from HashiCorp Consul
- Must avoid writing to intermediate files and reloading NGINX if possible
- Must not add more overhead by adding more services/config management
- While a watch might be preferred in some cases, it is ok for the first release, if upstreams are simply refreshed at a regular interval
SOLUTION
After researching pre-existing work and deciding we did not want to start with a C implementation we created a solution comprised of the following components: