Config for Service Discovery using DNS and SRV records?

I’m trying to use the new Service Discovery feature available in HAProxy 1.8 as described here:

I have HAProxy sitting in front of a collection of backend servers (which are Docker containers running on ECS) that are auto-scaled in and out during the day. I’ve got a Route53 private hosted zone with an SRV record and associated A records for the live instances to facilitate discovery.

$ dig -t srv _api._tcp.test-service.internal +additional

;; ANSWER SECTION:
_api._tcp.test-service.internal. 60 IN SRV	1 1 8080 i-XXXXXXXXXXXXXXXXX.test-service.internal.

What I’m not sure about is how to configure HAProxy for this. It seems like I need a combination of server-template, and resolvers, but I can’t get it to work. Here’s what I have so far:

resolvers awsdns
		nameserver dns0 "${SERVICE_DISCOVERY_DNS_SERVER0}"
		nameserver dns1 "${SERVICE_DISCOVERY_DNS_SERVER1}"
		nameserver dns2 "${SERVICE_DISCOVERY_DNS_SERVER2}"
		nameserver dns3 "${SERVICE_DISCOVERY_DNS_SERVER3}"

backend api
		option tcp-check
		server-template api 5 "_api._tcp.${SERVICE_DISCOVERY_DOMAIN_NAME}" 8080 resolvers awsdns resolve-prefer ipv4

But this doesn’t work. I suspect the server-template I have above is wrong somehow. Anyone have any working examples of DNS Service Discovery that can share their configs?

Thanks in advance!
BP

I got this working. The problem was I was trying to use the nameservers for the private hosted zone as my resolvers, when instead I needed to use the VPC internal DNS resolver. This is always the “+2” of configured CIDR range (http://blog.thestateofme.com/2015/09/01/forwarding-dns-queries-to-aws-vpc-resolvers/)

1 Like

Hi! Where you obtained the record prefix “_api._tcp.”.
Im trying to use with the AWS service discovery and the records that AWS created doesnt have the service and protocol prefix.

I didn’t use AWS’ Service Discovery for this (though I tried to). Gory details here: https://medium.com/ground-signal-engineering/ecs-service-discovery-with-lambda-dns-and-haproxy-1126ab381688