Skip to content

DNS Service Discovery#

DNS is a name resolution protocol used to determine IP addresses for hostnames. That makes it a natural fit for service discovery. Consul and AWS Cloud Map provide DNS resolutions for service discovery.

This page explains how Stork can use DNS to handle the service discovery.

DNS records#

DNS supports a variety of record types. Stork can resolve hostnames to addresses based on SRV, A and AAAA records. All these types of records may return multiple addresses for a single hostname.

While A and AAAA records are quite similar, they just carry an IP (v4 for A and v6 for AAAA), the SRV records are different. They contain a weight, a target and a port for a service instance. The target returned in an SRV record needs to be resolved further by an A or an AAAA record.

In short, it works as follows:

DNS service discovery DNS service discovery

Dependency#

To use the DNS service discovery, you need to add the Stork DNS Service Discovery provider dependency to your project:

<dependency>
    <groupId>io.smallrye.stork</groupId>
    <artifactId>stork-service-discovery-dns</artifactId>
    <version>1.3.2</version>
</dependency>

Configuration#

Next, set the service discovery type to dns. Additionally, you would usually specify the DNS server, or servers, to use for the discovery. All in all, your configuration could look as follows:

stork.my-service.service-discovery.type=dns
# optional dns servers:
stork.my-service.service-discovery.dns-servers=my-dns-server:8221,my-dns-server2
quarkus.stork.my-service.service-discovery.type=dns

# optional dns servers:
quarkus.stork.my-service.service-discovery.dns-servers=my-dns-server:8221,my-dns-server2

All the available parameters are as follows:

Attribute Mandatory Default Value Description
dns-servers No none Comma separated list of dns servers. Servers can either be in the server:port or just server form. Use none to use the system resolver.
hostname No The hostname to look up; if not defined Stork service name will be used.
record-type No SRV Type of the DNS record. A, AAAA and SRV records are supported
port No Port of the service instances. Required if the record type is other than SRV.
refresh-period No 5M Service discovery cache refresh period.
secure No Whether the connection with the service should be encrypted with TLS.
recursion-desired No true Whether DNS recursion is desired
dns-timeout No 5s Timeout for DNS queries
fail-on-error No false Whether an error in retrieving service instances from one of the DNS servers should cause a failure of the discovery attempt.