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