Nomad built-in DNS TTL and cache invalidation after allocation reschedule
0 reputation · 27 Apr 2023, 19:46 UTC
0 reputation · 27 Apr 2023, 19:46 UTC
Nomad provides an optional built-in DNS server for service and allocation name resolution under the nomad domain, with records derived from the catalog and allocation state.
API and inter-node RPC can be secured with TLS where server certificates must contain SANs matching advertised addresses and clients validate against a configured CA. DNS queries are served directly by Nomad servers and do not use the system resolver.
Configuration and defaults for DNS and TLS are component-specific and version-sensitive across major releases. An unresolved design consideration is how DNS TTL and cache invalidation interact with allocation rescheduling, and whether stale records can persist for clients until TTL expiry.
What TTL values are used for service and allocation records in the built-in DNS server, and can they be configured per service?
How does Nomad signal record removal or IP change to clients after an allocation is rescheduled, given DNS is served directly by servers?
Are there version-specific defaults for TLS verification and CA handling that affect DNS-based service discovery when TLS is enabled for the API?
35275 reputation · 28 Apr 2023, 04:32 UTC
Nomad's built-in DNS server uses fixed default TTL values for service and allocation records. These values are generally global and cannot be configured on a per-service basis. Because the DNS server is a lightweight utility integrated into the Nomad server, it does not support the granular record-level TTL overrides found in full-featured DNS providers like CoreDNS or BIND.
When an allocation is rescheduled, the Nomad server updates its internal state immediately. However, the built-in DNS server employs a passive invalidation model. It does not push updates to clients or signal the removal of records.
Clients will continue to receive the stale IP address until the TTL of the previous record expires. If the client environment employs its own caching layer (such as systemd-resolved on Linux or the JVM's internal DNS cache), the record may persist even longer than the TTL specified by the Nomad server.
To determine the exact TTL currently served by your cluster and observe the propagation delay during a reschedule, use the following method:
dig @<nomad-server-ip> <service-name&>.nomad
nomad alloc stop) and repeatedly query the DNS server to measure the delta between the allocation becoming healthy and the DNS record updating.There is no functional overlap between the TLS configuration used for the Nomad HTTP API/RPC and the built-in DNS server. DNS queries are served over standard UDP/TCP port 53 and are unencrypted. Enabling TLS for the API or configuring CA certificates for server-to-server communication does not affect DNS resolution or the validity of DNS-based service discovery.
This behavior assumes a standard Nomad server deployment where the dns block is enabled. We assume the client is querying the Nomad server directly; if a recursive resolver is placed between the client and Nomad, that resolver's own caching policies will override Nomad's TTL.
Missing Diagnostic Detail: Are you using a language runtime with a known aggressive DNS cache (e.g., Java/JVM)? If so, the perceived stale record duration is likely a client-side configuration issue rather than a Nomad server TTL limitation.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.