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:

    1. {
    2. "id": 1,
    3. "discovery_type": "dns",
    4. "service_name": "test.consul.service",
    5. }

    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:

    1. {
    2. "id": 1,
    3. "discovery_type": "dns",
    4. "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:

    1. {
    2. "id": 1,
    3. "discovery_type": "dns",
    4. "service_name": "srv.blah.service",
    5. "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”.