DNS
First of all, we need to configure the address of DNS servers:
Unlike configuring the domain in the Upstream’s field, service discovery via DNS will return all records. For example, with upstream configuration:
{
"id": 1,
"discovery_type": "dns",
"service_name": "test.consul.service",
}
and test.consul.service
be resolved as and 1.1.1.2
, this result will be the same as:
Note that all the IPs from test.consul.service
share the same weight.
If you want to specify the port for the upstream server, you can add it to the service_name
:
{
"id": 1,
"discovery_type": "dns",
"type": "roundrobin"
Another way to do it is via the SRV record, see below.
By using SRV record you can specify the port and the weight of a service.
Assumed you have the SRV record like this:
{
"id": 1,
"discovery_type": "dns",
"service_name": "srv.blah.service",
"type": "roundrobin"
is the same as:
Note that two records of domain B split the weight evenly. For SRV record, nodes with lower priority are chosen first, so the final priority is negative.
As for 0 weight SRV record, the RFC 2782 says:
For SRV record which has port 0, we will fallback to use the upstream protocol’s default port. You can also specify the port in the “service_name” field directly, like “srv.blah.service:8848”.