Read endpoints from DNS
The dns sourceWhere a service reads its endpoints, one of dns, file, url or kubernetes. See Services and sources. turns DNS records into endpointsOne IP address and port that a service gives, with its load balancing weight. See HTTP API.. It suits services already published in DNS, by your own zones or by a
registry such as Consul. This guide covers its three lookups and the resolver key. Consul has its own guide, Read
Consul services.
type | Use it when |
|---|---|
IP (default) | Every address of a name listens on the same port. |
SRV | Each endpoint has its own port or weight, published as SRVA DNS record giving the host, port and weight of one instance of a service. See Read endpoints from DNS. records. |
TXT | You want to write the endpoints in your zone without SRV, one eds= record each. |
Serve the addresses of a name
Section titled “Serve the addresses of a name”With type: IP, Vigie looks up the A and AAAA records of name and gives each address on the default_port of the
service, with a weight of 0.
servicesservices
Type list · Required yes · Default none
Services the server answers for, at least one.
: - nameservices[].name
Type string · Required yes · Default none
Name clients ask for. A request without a name gets the service named default.
: web default_portservices[].default_port
Type integer · Required no · Default 80
Port of the endpoints that don’t give their own.
: 8080 dnsservices[].dns
Type object · Required one source · Default none
Reads the endpoints from DNS.
: nameservices[].dns.name
Type string · Required yes · Default none
DNS name to look up.
: web.example.comIf web.example.com has the A records 10.0.0.5 and 10.0.0.6, the service gives 10.0.0.5:8080 and 10.0.0.6:8080.
Serve the targets of SRV records
Section titled “Serve the targets of SRV records”With type: SRV, Vigie looks up _<srv_service>._<srv_proto>.<name>, then the addresses of each target. Each address
takes the port and the weight of its record. A record with port 0 takes the default_port.
-
Publish the SRV records in your zone.
_http._tcp.api.example.com. 300 IN SRV 10 5 8080 api-1.example.com._http._tcp.api.example.com. 300 IN SRV 10 1 8080 api-2.example.com. -
Point the service at them.
srv_serviceandsrv_protodefault tohttpandtcp.config.yml servicesservicesType list · Required yes · Default none
Services the server answers for, at least one.
:- nameservices[].nameType string · Required yes · Default none
Name clients ask for. A request without a name gets the service named
: apidefault.default_portservices[].default_portType integer · Required no · Default
80Port of the endpoints that don’t give their own.
: 8080dnsservices[].dnsType object · Required one source · Default none
Reads the endpoints from DNS.
:nameservices[].dns.nameType string · Required yes · Default none
DNS name to look up.
: api.example.comtypeservices[].dns.typeType string · Required no · Default
IP
: SRVIP,SRVorTXT, in any case.srv_serviceservices[].dns.srv_serviceType string · Required no · Default
httpwithSRVService part of the SRV lookup.
: httpsrv_protoservices[].dns.srv_protoType string · Required no · Default
tcpwithSRVProtocol part of the SRV lookup.
: tcp
The service gives each address of api-1.example.com with weight 5 and each address of api-2.example.com with
weight 1, both on port 8080. Vigie ignores the priority of the records.
Write endpoints in TXT records
Section titled “Write endpoints in TXT records”With type: TXT, Vigie reads the TXT records of name and keeps those that start with eds=. The rest of each record
is an endpoint line, host[:port][#weight], so a TXT record can carry a
port and a weight without SRV.
-
Publish one record per endpoint.
db.example.com. 300 IN TXT "eds=10.0.1.10:5432#2"db.example.com. 300 IN TXT "eds=10.0.1.11:5432#1"db.example.com. 300 IN TXT "v=spf1 -all" -
Point the service at the name.
config.yml servicesservicesType list · Required yes · Default none
Services the server answers for, at least one.
:- nameservices[].nameType string · Required yes · Default none
Name clients ask for. A request without a name gets the service named
: dbdefault.default_portservices[].default_portType integer · Required no · Default
80Port of the endpoints that don’t give their own.
: 5432dnsservices[].dnsType object · Required one source · Default none
Reads the endpoints from DNS.
:nameservices[].dns.nameType string · Required yes · Default none
DNS name to look up.
: db.example.comtypeservices[].dns.typeType string · Required no · Default
IP
: TXTIP,SRVorTXT, in any case.
The service gives the two endpoints and skips the SPF record. Write IP addresses in the records, because Vigie doesn’t resolve the host of a line.
Query a given DNS server
Section titled “Query a given DNS server”Without resolver, Vigie uses the resolverThe DNS server a dns source queries over TCP instead of the resolver of the system. See Read endpoints from DNS. of the system. Set resolver to send every lookup of the service to one DNS
server instead, the lookups of the SRV targets included:
servicesservices
Type list · Required yes · Default none
Services the server answers for, at least one.
: - nameservices[].name
Type string · Required yes · Default none
Name clients ask for. A request without a name gets the service named default.
: api default_portservices[].default_port
Type integer · Required no · Default 80
Port of the endpoints that don’t give their own.
: 8080 dnsservices[].dns
Type object · Required one source · Default none
Reads the endpoints from DNS.
: nameservices[].dns.name
Type string · Required yes · Default none
DNS name to look up.
: api.example.com typeservices[].dns.type
Type string · Required no · Default IP
IP, SRV or TXT, in any case.
: SRV resolverservices[].dns.resolver
Type host:port · Required no · Default empty
DNS server to query instead of the resolver of the system, such as 127.0.0.1:8600. An IPv6 address goes in brackets, [::1]:8600.
: 10.0.0.53:53Vigie then asks that server over TCP, which keeps a long answer whole where UDP could cut it, and gives up after 8
seconds. An IPv6 server goes in brackets, such as [fd00::53]:53.
Check the result
Section titled “Check the result”-
Check the file and reloadReading the configuration file again to replace the services, on
SIGHUPorPOST /reload. See Reload the services. the services, see Reload the services. -
Ask for the service.
Terminal window curl -s 'http://localhost:8080/services?service_name=api'
A name that doesn’t resolve answers 500 with resolve service api failed: and the error of the lookup. Compare with
dig, against the same server when you set resolver:
dig +tcp @10.0.0.53 -p 53 _http._tcp.api.example.com SRVVigie keeps each answer for cache_ttl, 5 seconds by default, whatever the TTL of the records.
Configuration lists every key of the source.