I am attempting to perform load-balancing with HAProxy with services registered in Consul, using Consul's DNS SRV records.
My Consul DNS is properly configured to resolve the following:
$ dig my-service.service.consul SRV
...
;; ANSWER SECTION:
my-service.service.consul. 0 IN SRV 1 1 8000 node1.node.dc.consul.
;; ADDITIONAL SECTION:
node1.node.dc.consul. 10 IN A X.X.X.X
node1.node.dc.consul. 10 IN TXT "consul-network-segment="
And also with a Consul prepared query:
$ dig geo-my-service.query.consul SRV
...
;; ANSWER SECTION:
geo-my-service.query.consul. 10 IN SRV 1 1 8000 node1.node.dc.consul.
;; ADDITIONAL SECTION:
node1.node.dc.consul. 10 IN A X.X.X.X
node1.node.dc.consul. 10 IN TXT "consul-network-segment="
I successfully configured the barebone service query in HAProxy with the following block:
backend my-service
balance roundrobin
server-template my-service-api 1 _my-service._tcp.service.consul check resolvers consul
However, when I use the Consul prepared query, I get a Socket error: No port available for the TCP connection error on the given service in HAProxy:
backend companion_authnz
balance roundrobin
server-template my-service-api 1 _geo-my-service._tcp.query.consul check resolvers consul
I cannot find any information in neither HAProxy nor Consul documentation about resolving prepared queries in HAProxy.
Has anyone ever had experience with Consul prepared queries and plugging them in HAProxy using SRV records?
I am using Consul 1.1.0 and HAProxy 1.8.9. Thanks!
EDIT:
I successfully plugged a prepared query in HAProxy by using A records and specifying the service port in the config file:
backend my-service
balance roundrobin
server-template my-service-api 1 geo-my-service.query.consul:8000 check resolvers consul
However, that would be nice to use SRV records in order for the port to be dynamically resolved by HAProxy.