From 4b1ed38b417e438be061aff1b36bf93ac39458bc Mon Sep 17 00:00:00 2001 From: "J.C. Jones" Date: Fri, 30 Jun 2023 14:08:24 -0700 Subject: [PATCH] Document that DNS lookups can target cluster peers Static DNS lookups, in addition to explicitly targeting a datacenter, can target a cluster peer. This was added in 95dc0c7b301b70a6b955a8b7c9737c9b86f03df6 but didn't make the documentation. The driving function for the change is `parseLocality` here: https://github.com/hashicorp/consul/blob/0b1299c28d8127129d61310ee4280055298438e0/agent/dns_oss.go#L25 The biggest change in this is to adjust the standard lookup syntax to tie `.` to `.dc` as required-together, and to append in the similar `..peer` optional argument, both to A record and SRV record lookups. --- .../services/discovery/dns-static-lookups.mdx | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/website/content/docs/services/discovery/dns-static-lookups.mdx b/website/content/docs/services/discovery/dns-static-lookups.mdx index 6f2db4108c37..353f4e2628e3 100644 --- a/website/content/docs/services/discovery/dns-static-lookups.mdx +++ b/website/content/docs/services/discovery/dns-static-lookups.mdx @@ -97,16 +97,18 @@ The DNS protocol limits the size of requests, even when performing DNS TCP queri Consul randomizes DNS SRV records and ignores weights specified in service configurations when printing responses. If records are truncated, each client using weighted SRV responses may have partial and inconsistent views of instance weights. As a result, the request distribution may be skewed from the intended weights. We recommend calling the [`/catalog/nodes` API endpoint](/consul/api-docs/catalog#list-nodes) to retrieve the complete list of nodes. You can apply query parameters to API calls to sort and filter the results. ### Standard lookups -To perform standard service lookups, specify tags, the name of the service, datacenter, and domain using the following syntax to query for service providers: +To perform standard service lookups, specify tags, the name of the service, datacenter, cluster peer, and domain using the following syntax to query for service providers: ```text -[.].service[.].dc. +[.].service[..dc][..peer]. ``` The `tag` subdomain is optional. It filters responses so that only service providers containing the tag appear. The `datacenter` subdomain is optional. By default, Consul interrogates the querying agent's datacenter. +The `cluster-peer` name is optional, and specifies the [cluster peer](/consul/docs/connect/cluster-peering) whose [exported services](/consul/docs/connect/config-entries/exported-services) should be the target of the query. + By default, the lookups query in the `consul` domain. Refer to [Configure DNS Behaviors](/consul/docs/services/discovery/dns-configuration) for information about using alternate domains. #### Standard lookup results @@ -195,6 +197,38 @@ _rabbitmq._amqp.service.consul. 0 IN SRV 1 1 5672 rabbitmq.node1.dc1.consul. ;; ADDITIONAL SECTION: rabbitmq.node1.dc1.consul. 0 IN A 10.1.11.20 ``` + +You can also perform RFC 2782 lookups that target a specific [cluster peer](/consul/docs/connect/cluster-peering) or datacenter by including `.dc` or `.peer` in the query labels: + +```text +_._[.service][..dc][..peer]. +``` + +The following example queries the `redis` service tagged with `tcp` for the cluster peer `phx1`, which returns two instances, one at `10.1.11.83:29081` and one at `10.1.11.86:29142`: + +```shell-session +dig @127.0.0.1 -p 8600 _redis._tcp.service.phx1.peer.consul SRV + +; <<>> DiG 9.18.15 <<>> @127.0.0.1 -p 8600 _redis._tcp.service.phx1.peer.consul SRV +;; global options: +cmd +;; Got answer: +;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 40572 +;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 2 + +;; OPT PSEUDOSECTION: +; EDNS: version: 0, flags:; udp: 1232 +;; QUESTION SECTION: +;_redis._tcp.service.phx1.peer.consul. IN SRV + +;; ANSWER SECTION: +_redis._tcp.service.phx1.peer.consul. 0 IN SRV 1 1 29081 0a000d53.addr.consul. +_redis._tcp.service.phx1.peer.consul. 0 IN SRV 1 1 29142 0a010d56.addr.consul. + +;; ADDITIONAL SECTION: +0a000d53.addr.consul. 0 IN A 10.1.11.83 +0a010d56.addr.consul. 0 IN A 10.1.11.86 +``` + #### SRV responses for hosts in the .addr subdomain If a service registered with Consul is configured with an explicit IP address or addresses in the [`address`](/consul/docs/services/configuration/services-configuration-reference#address) or [`tagged_address`](/consul/docs/services/configuration/services-configuration-reference#tagged_address) parameter, then Consul returns the hostname in the target field of the answer section for the DNS SRV query according to the following format: