Re: Dynamic server name with HAProxy, based on original hostname

2017-09-18 Thread Lukas Tribus
Hello,


Am 17.09.2017 um 23:11 schrieb Ludovic Gasc:
>
>  
>
> 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.

As per:
https://cbonte.github.io/haproxy-dconv/1.7/configuration.html#5.2-init-addr

Use:
init-addr last,libc,none

to avoid failing on adress resolution errors. Remove libc if you only want 
dynamic DNS.
"none" at the end is the important keyword here.

Also make sure you use recent code, as DNS resolution has had its issues.

If in doubt, check:
http://www.haproxy.org/bugs/


cheers,
lukas




Re: Dynamic server name with HAProxy, based on original hostname

2017-09-18 Thread Ludovic Gasc
It isn't really the use case we need.

Is it possible to open an issue somewhere with this idea ?
I didn't see a bug tracker for haproxy.

Regards.

--
Ludovic Gasc (GMLudo)
Lead Developer Architect at ALLOcloud
https://be.linkedin.com/in/ludovicgasc

2017-09-18 2:21 GMT+02:00 Igor Cicimov :

> On Mon, Sep 18, 2017 at 7:11 AM, Ludovic Gasc  wrote:
>
>> 2017-09-17 11:16 GMT+02:00 Igor Cicimov :
>>
>>> 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: resolvers dns check inter 1000
> init-addr last,libc,127.0.0.1
>
> backend bk_svc_2
>   server svc2 service2.service.local: resolvers dns check inter 1000
> init-addr last,libc,127.0.0.1
> .
> .
> .
> backend bk_svc_n
>   server svcn servicen.service.local: resolvers dns check inter 1000
> init-addr last,libc,127.0.0.1
>
> backend bk_unknown_domain
>  
>
>
> 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
>


Re: Dynamic server name with HAProxy, based on original hostname

2017-09-17 Thread Igor Cicimov
On Mon, Sep 18, 2017 at 7:11 AM, Ludovic Gasc  wrote:

> 2017-09-17 11:16 GMT+02:00 Igor Cicimov :
>
>> 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: resolvers dns check inter 1000
init-addr last,libc,127.0.0.1

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

backend bk_unknown_domain
 


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


Re: Dynamic server name with HAProxy, based on original hostname

2017-09-17 Thread Ludovic Gasc
2017-09-17 11:16 GMT+02:00 Igor Cicimov :

> 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.


>
> On Sat, Sep 16, 2017 at 1:11 AM, Ludovic Gasc  wrote:
>
>> I have tested with HAProxy 1.7.
>>
>> Where you see that it's a feature of 1.8 ?
>> You mean I could try my piece of configuration on HAProxy 1.8, it should
>> work ?
>>
>> Regards.
>>
>>
>> 2017-09-15 14:47 GMT+02:00 Igor Cicimov :
>>
>>>
>>>
>>> On Fri, Sep 15, 2017 at 9:25 PM, Ludovic Gasc  wrote:
>>>
 Hi,

 I imagine that if I have no answer, it's because it isn't possible with
 HAProxy ?

 Thanks for your return.


 2017-09-10 22:27 GMT+02:00 Ludovic Gasc :

> Hi,
>
> I'm trying to reproduce this Nginx configuration with HAProxy:
> https://memz.co/reverse-proxy-nginx-docker-microservices/
>
> Where it's possible to use DNS as dynamic list to proxy to the right
> server.
> Our use case isn't container-related, but simply to move easily a
> customer from a backend server to another one, without to change the
> HAproxy configuration.
>
> The closest feature in HAProxy seems to be option http_proxy, however,
> no DNS lookup is performed:
> http://cbonte.github.io/haproxy-dconv/configuration-1.7.html
> #4.2-option%20http_proxy
>
> I have tried to use a resolver in haproxy configuration + in backend
> section:
>   server XX %[hdr(host)]: resolvers dns
> check inter 1000 init-addr last,libc,127.0.0.1
>
> However, it doesn't work.
>
> Maybe with a lua script it's possible to implement that, but I would
> prefer to have a simple configuration like with Nginx.
>
> Do I missed something ?
>
> BTW, thanks for HAProxy, I like a lot this product ;-)
>
> Regards.
> --
> Ludovic Gasc (GMLudo)
>


>>> ​This should be a feature in 1.8, which version did you try?​
>>>
>>>
>>
>
>


Re: Dynamic server name with HAProxy, based on original hostname

2017-09-17 Thread Igor Cicimov
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.

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.

On Sat, Sep 16, 2017 at 1:11 AM, Ludovic Gasc  wrote:

> I have tested with HAProxy 1.7.
>
> Where you see that it's a feature of 1.8 ?
> You mean I could try my piece of configuration on HAProxy 1.8, it should
> work ?
>
> Regards.
>
>
> 2017-09-15 14:47 GMT+02:00 Igor Cicimov :
>
>>
>>
>> On Fri, Sep 15, 2017 at 9:25 PM, Ludovic Gasc  wrote:
>>
>>> Hi,
>>>
>>> I imagine that if I have no answer, it's because it isn't possible with
>>> HAProxy ?
>>>
>>> Thanks for your return.
>>>
>>>
>>> 2017-09-10 22:27 GMT+02:00 Ludovic Gasc :
>>>
 Hi,

 I'm trying to reproduce this Nginx configuration with HAProxy:
 https://memz.co/reverse-proxy-nginx-docker-microservices/

 Where it's possible to use DNS as dynamic list to proxy to the right
 server.
 Our use case isn't container-related, but simply to move easily a
 customer from a backend server to another one, without to change the
 HAproxy configuration.

 The closest feature in HAProxy seems to be option http_proxy, however,
 no DNS lookup is performed:
 http://cbonte.github.io/haproxy-dconv/configuration-1.7.html
 #4.2-option%20http_proxy

 I have tried to use a resolver in haproxy configuration + in backend
 section:
   server XX %[hdr(host)]: resolvers dns
 check inter 1000 init-addr last,libc,127.0.0.1

 However, it doesn't work.

 Maybe with a lua script it's possible to implement that, but I would
 prefer to have a simple configuration like with Nginx.

 Do I missed something ?

 BTW, thanks for HAProxy, I like a lot this product ;-)

 Regards.
 --
 Ludovic Gasc (GMLudo)

>>>
>>>
>> ​This should be a feature in 1.8, which version did you try?​
>>
>>
>


Re: Dynamic server name with HAProxy, based on original hostname

2017-09-15 Thread Ludovic Gasc
I have tested with HAProxy 1.7.

Where you see that it's a feature of 1.8 ?
You mean I could try my piece of configuration on HAProxy 1.8, it should
work ?

Regards.

2017-09-15 14:47 GMT+02:00 Igor Cicimov :

>
>
> On Fri, Sep 15, 2017 at 9:25 PM, Ludovic Gasc  wrote:
>
>> Hi,
>>
>> I imagine that if I have no answer, it's because it isn't possible with
>> HAProxy ?
>>
>> Thanks for your return.
>>
>>
>> 2017-09-10 22:27 GMT+02:00 Ludovic Gasc :
>>
>>> Hi,
>>>
>>> I'm trying to reproduce this Nginx configuration with HAProxy:
>>> https://memz.co/reverse-proxy-nginx-docker-microservices/
>>>
>>> Where it's possible to use DNS as dynamic list to proxy to the right
>>> server.
>>> Our use case isn't container-related, but simply to move easily a
>>> customer from a backend server to another one, without to change the
>>> HAproxy configuration.
>>>
>>> The closest feature in HAProxy seems to be option http_proxy, however,
>>> no DNS lookup is performed:
>>> http://cbonte.github.io/haproxy-dconv/configuration-1.7.html
>>> #4.2-option%20http_proxy
>>>
>>> I have tried to use a resolver in haproxy configuration + in backend
>>> section:
>>>   server XX %[hdr(host)]: resolvers dns
>>> check inter 1000 init-addr last,libc,127.0.0.1
>>>
>>> However, it doesn't work.
>>>
>>> Maybe with a lua script it's possible to implement that, but I would
>>> prefer to have a simple configuration like with Nginx.
>>>
>>> Do I missed something ?
>>>
>>> BTW, thanks for HAProxy, I like a lot this product ;-)
>>>
>>> Regards.
>>> --
>>> Ludovic Gasc (GMLudo)
>>>
>>
>>
> ​This should be a feature in 1.8, which version did you try?​
>
>


Re: Dynamic server name with HAProxy, based on original hostname

2017-09-15 Thread Igor Cicimov
On Fri, Sep 15, 2017 at 9:25 PM, Ludovic Gasc  wrote:

> Hi,
>
> I imagine that if I have no answer, it's because it isn't possible with
> HAProxy ?
>
> Thanks for your return.
>
>
> 2017-09-10 22:27 GMT+02:00 Ludovic Gasc :
>
>> Hi,
>>
>> I'm trying to reproduce this Nginx configuration with HAProxy:
>> https://memz.co/reverse-proxy-nginx-docker-microservices/
>>
>> Where it's possible to use DNS as dynamic list to proxy to the right
>> server.
>> Our use case isn't container-related, but simply to move easily a
>> customer from a backend server to another one, without to change the
>> HAproxy configuration.
>>
>> The closest feature in HAProxy seems to be option http_proxy, however, no
>> DNS lookup is performed:
>> http://cbonte.github.io/haproxy-dconv/configuration-1.7.
>> html#4.2-option%20http_proxy
>>
>> I have tried to use a resolver in haproxy configuration + in backend
>> section:
>>   server XX %[hdr(host)]: resolvers dns check
>> inter 1000 init-addr last,libc,127.0.0.1
>>
>> However, it doesn't work.
>>
>> Maybe with a lua script it's possible to implement that, but I would
>> prefer to have a simple configuration like with Nginx.
>>
>> Do I missed something ?
>>
>> BTW, thanks for HAProxy, I like a lot this product ;-)
>>
>> Regards.
>> --
>> Ludovic Gasc (GMLudo)
>>
>
>
​This should be a feature in 1.8, which version did you try?​


Re: Dynamic server name with HAProxy, based on original hostname

2017-09-15 Thread Ludovic Gasc
Hi,

I imagine that if I have no answer, it's because it isn't possible with
HAProxy ?

Thanks for your return.

2017-09-10 22:27 GMT+02:00 Ludovic Gasc :

> Hi,
>
> I'm trying to reproduce this Nginx configuration with HAProxy:
> https://memz.co/reverse-proxy-nginx-docker-microservices/
>
> Where it's possible to use DNS as dynamic list to proxy to the right
> server.
> Our use case isn't container-related, but simply to move easily a customer
> from a backend server to another one, without to change the HAproxy
> configuration.
>
> The closest feature in HAProxy seems to be option http_proxy, however, no
> DNS lookup is performed:
> http://cbonte.github.io/haproxy-dconv/configuration-1.
> 7.html#4.2-option%20http_proxy
>
> I have tried to use a resolver in haproxy configuration + in backend
> section:
>   server XX %[hdr(host)]: resolvers dns check
> inter 1000 init-addr last,libc,127.0.0.1
>
> However, it doesn't work.
>
> Maybe with a lua script it's possible to implement that, but I would
> prefer to have a simple configuration like with Nginx.
>
> Do I missed something ?
>
> BTW, thanks for HAProxy, I like a lot this product ;-)
>
> Regards.
> --
> Ludovic Gasc (GMLudo)
>