I’m building a new project with Nomad and want to use HaProxy as my facing reserve proxy for a public API (performance, reliability and i have some experience with it).
For this specific API, i want the best performance i can (so preferring HaProxy over Caddy and Traefik for example).
I have a 1st working version with Nomad, Consul and HaProxy but i would like to remove Consul. After reading some documentation with the steps to deploy/maintain it in production … i would like to avoid this if i can.
In my current configuration, HaProxy knows where to « route » request thanks to haproxy server-template directive and DNS resolution … provided by Consul.
This is totally possible, however, Nomad does not currently provide a native DNS lookup feature with its service discovery functionality. The way to achieve this would be to utilise Nomad’s template block from within the HAProxy job and use the consul-template Nomad API lookup functions to lookup services that you wish to route to from the HAProxy instance. This would then write a config file that HAProxy loads; changes to the config could then use the template signal configuration options to send a SIGHUP signal to HAProxy to inform it to reload its configuration.
Note that for the SIGHUP signal to work i had to mount the haproxy directory (containing he haproxy.cfg) and not the file only.
Hope that would help anyone passing by.
Two points that i’d like to improve/understand :
Is there a unique service ID or way to generate a unique service name to use in the template ? I had to concatenate the word ‘server’ with the IP address ({{.Name}}-{{.Address}}) to generate something unique to give to HaProxy (i played with range, loop … with no success).
When i increase/decrease my target service count, i can see that my HaProxy is reloading its conf (via logs) and the HaProxy allocation is not killed but the template is sometimes rendered 2 times. Is it normal (rendering 2 times) ?
Sorry for being dense, but I am not seeing your concatenation of the word “server” in your Nomad specific config – other than the obvious usage of it while declaring a timeout and backend … That said, if you happen to be referring to the declaration of an HAProxy backend server, I have used the below config with success, to ensure a unique server name for every allocation instance of a specific Nomad service ::
server {{.Name}}-{{.Address}}-{{.Port}} {{.Address}}:{{.Port}} check
This is normal for me, especially when scaling up/down a target service count in our Nomad sandbox, with limited resources … The best way I can explain it (have observed) – is that a template is re-rendered for every change in allocation count for a specific service … For example, scaling from 1-to-3 allocations, I have consistently seen the template re-render 2 times … I haven’t had time to test this theory, but possibly extending splay may reduce the number of times a template is re-rendered – if that is a goal of yours …
Hi @gkspranger and thanks for your feedback.
Indeed there was a typo in my message and i was/am not able to update it. I wanted to write : « After the word server, I had to concatenate the word ‘server’ with the IP address ({{.Name}}-{{.Address}} ) to generate something unique … »
I followed your advice and added the port to the concatenation.
However having a kind of unique identifier for this specific service instance would have been better.
Regarding the second point i was just curious wether that was a bug or not.