On Mon, Sep 18, 2017 at 7:11 AM, Ludovic Gasc <[email protected]> wrote:

> 2017-09-17 11:16 GMT+02:00 Igor Cicimov <[email protected]>:
>
>> In 1.8 haproxy takes all records returned by the dns resolver into
>> account where is in 1.7 only the first one in the list. That's the
>> difference I was referring to in my previous comment. Having this in mind
>> your setup might not work as you expect in case when your service has more
>> than one endpoint.
>>
>
> Indeed, it doesn't help me.
>
>
>> Regarding your specific example, what exactly is not working? Haproxy
>> will perform dns resolution on startup and my guess would be it throws an
>> error since %[hdr(host)] at that point is empty.
>>
>
> Exactly.
> No idea to avoid that.
>

​Try something like this, creating separate backend per service:​

​frontend fe_web
  ...
  ​use_backend
%[req.hdr(host),lower,map_dom(/etc/haproxy/domains.map,bk_unknown_domain)]

backend bk_svc_1
  server svc1 service1.service.local:8888 resolvers dns check inter 1000
init-addr last,libc,127.0.0.1

backend bk_svc_2
  server svc2 service2.service.local:8888 resolvers dns check inter 1000
init-addr last,libc,127.0.0.1
.
.
.
backend bk_svc_n
  server svcn servicen.service.local:8888 resolvers dns check inter 1000
init-addr last,libc,127.0.0.1

backend bk_unknown_domain
 <what_ever_here>


and have in your /etc/haproxy/domains.map map file:

service1.domain.com bk_svc_1
service2.domain.com bk_svc_2
...
servicen.domain.com bk_svc_n


It is not that dynamic though as in the Nginx example you linked to since
you have to maintain the map file and insert new backend per service but
nothing that cant be solved with some CM tool if needed. Maybe even avoid
the map file if you prefer it that way and have the backend named as the
Host header:

frontend
  use_backend %[req.hdr(host)]
  default_backend bk_unknown_domain

backend service1.domain.com
backend service2.domain.com
...
backend bk_unknown_domain


Igor

Reply via email to