Service Discovery
Service Discovery maintains the Service Discovery Catalog, a live record of every component of the a9s Data Services Framework and of every Service Instance. The Service Discovery Catalog stays current through topology changes, such as VMs going down, through cluster operations and changes in cluster health, such as failovers, and through network reassignments. It also records the health of every VM, based on the jobs that run on it.
The Service Discovery Catalog is consumed through DNS, as names in the discovery domain. This is crucial for external networks, such as the network where Cloud Foundry applications run, that need to reach the services in the framework's network.
Service Discovery is built on Consul, but it is not a standalone product. It comprises the
consul-dns deployment, the Discovery Agents on every VM and their configuration, and it
provides service discovery for the framework and its Service Instances only. It is not offered, supported or intended
for standalone use as a general-purpose service discovery or service networking solution.
Based on the Service Discovery Catalog, Service Discovery provides:
- Primary aliases: a name that always points to the current primary node of a cluster.
- Load balancing: names that resolve to all healthy nodes of a Service Instance.
- Membership: every VM joins one cluster, so the framework knows which nodes exist and which of them are alive.
- Discovery: framework components and Service Instances are found by name.
- Health-based operations: failovers and load balancing are driven by health checks.
Components
The Service Discovery Catalog is the record of all nodes and services of the framework and of its Service
Instances, together with the results of their health checks. Names in the discovery domain (iaas.consul.domain) are
answered from the Service Discovery Catalog.
The consul-dns deployment consists of:
- Service Discovery Servers: three Consul VMs that maintain the Service Discovery Catalog.
- Dnsmasq VMs: three VMs, each with a Discovery Agent, through which the discovery domain is made resolvable from external networks.
A Discovery Agent (see The Discovery Agent) runs on every other VM of the framework and of its Service Instances, the Dnsmasq VMs included. It registers the VM's services and health checks in the Service Discovery Catalog, and answers names in the discovery domain on the VM itself. The traffic between the Discovery Agents and the Service Discovery Servers is encrypted and secured with TLS. By default, the DNS interface and the HTTP API of a Discovery Agent listen only on the loopback interface.
The Discovery Agent
The Discovery Agent is configured to fit the needs of the a9s Data Services Framework. It runs as the consul job on
every VM of the framework and of its Service Instances, and it is not intended to be used, configured or operated on its
own. Wherever "the Discovery Agent" is mentioned in this documentation, this agent is meant.
External Name Resolution
The Dnsmasq VMs answer names in the discovery domain through their local Discovery Agents, and forward all other queries
to upstream nameservers (iaas.consul.dnsmasq.upstream_nameservers). The discovery domain is delegated to them by the
platform's nameservers, or the Dnsmasq VMs are configured as the platform's nameservers, as described in
3.3. Make Service Discovery Available in the Application Platform.
The Dnsmasq VMs are intentionally separate from the Service Discovery Servers. This way, name resolution for external parties is scaled with the Dnsmasq VMs, without scaling the Service Discovery Servers, whose performance could otherwise be impacted.
Using the Discovery Agent to consume the Service Discovery Catalog from an external system is not supported. It is built for the framework only and can change in ways that break such a use at any time. An external system can join the cluster with a Consul agent of its own, using the cluster's encryption key and certificates, but the recommended way is the DNS interface of the Dnsmasq VMs. Every additional agent counts toward the size of the cluster, and the setup, credentials and updates of such an agent must be maintained by the operators. For more information, see Concerns.
BOSH DNS and Service Discovery
BOSH DNS is a BOSH release that adds a DNS server running locally on
every VM, and health-aware queries for BOSH domains, on top of BOSH's native DNS, which is
provided by the BOSH Agents. BOSH DNS is commonly used by operators, usually as an add-on.
The job of the Discovery Agent adds nameserver 127.0.0.1 to /etc/resolv.conf on its VM, and where BOSH DNS runs, the
Discovery Agent hooks into it as described below.
How Discovery Agents Hook into BOSH DNS
A handler file, dns/handlers.json, is shipped by the job of the Discovery Agent on every VM, and read by BOSH DNS when
it starts. It forwards the discovery domain (iaas.consul.domain) to the local Discovery Agent on its DNS port,
127.0.0.1:53 by default. Caching is disabled for this domain.
The handler file is shipped because consul.add_consul_to_bosh_dns_resolvers is set to true for every Discovery
Agent, including those of the Service Instances. The property is enabled to make every VM of the framework and of its
Service Instances compatible with BOSH DNS, as newer stemcells may require BOSH DNS on every VM. It must not be set to
false. For more information, see Properties.
- A BOSH DNS add-on that runs BOSH DNS without BPM must not carry a handler of its own for the discovery domain
(
iaas.consul.domain, for exampleconsul.dsf2), as two handlers for the same domain are error-prone. - A BOSH DNS add-on must exclude the deployment of Service Discovery (
consul-dns), as the Dnsmasq VMs are not compatible with BOSH DNS.
BOSH DNS with BPM
BOSH DNS reads the handler file of the Discovery Agent only when it runs without BPM. With BPM, the discovery domain is not forwarded to the Discovery Agent by BOSH DNS. Platform Operators can add a handler for the discovery domain to their BOSH DNS add-on, but this can cause issues: only BOSH DNS without BPM is supported.
Service Instances
For the a9s Service Instances, Service Discovery provides the following infrastructure- and Data Service-independent functionality:
-
Service Bindings: a9s service bindings use names in the discovery domain instead of IP addresses. Application Developers do not have to update their bindings when, for example, an IP address of an instance node changes or another instance node takes over after a failover.
-
Network Relocations: when the nodes of a Service Instance are moved to a new network, some nodes remain in the old network while the others already run in the new one. As the Service Discovery Catalog follows network reassignments, as described at the beginning of this page, the nodes keep reaching each other during this transition, as long as communication between the networks is configured in the infrastructure.