2014-02-25 20:22:25 +00:00
|
|
|
---
|
2020-04-07 18:55:19 +00:00
|
|
|
layout: docs
|
|
|
|
page_title: External Services
|
|
|
|
sidebar_current: docs-guides-external
|
|
|
|
description: >-
|
|
|
|
Very few infrastructures are entirely self-contained. Most rely on a multitude
|
|
|
|
of external service providers. Consul supports this by allowing for the
|
|
|
|
definition of external services, services that are not provided by a local
|
|
|
|
node.
|
2014-02-25 20:22:25 +00:00
|
|
|
---
|
|
|
|
|
|
|
|
# Registering an External Service
|
|
|
|
|
2015-02-28 00:00:13 +00:00
|
|
|
Very few infrastructures are entirely self-contained. Most rely on a multitude
|
|
|
|
of external service providers. Consul supports this by allowing for the definition
|
2018-01-12 21:23:16 +00:00
|
|
|
of external services, services that are not provided by a local node. There's also a
|
|
|
|
companion project called [Consul ESM](https://github.com/hashicorp/consul-esm) which
|
|
|
|
is a daemon that functions as an external service monitor that can help run health
|
|
|
|
checks for external services.
|
2014-02-25 20:22:25 +00:00
|
|
|
|
2015-02-28 00:00:13 +00:00
|
|
|
Most services are registered in Consul through the use of a
|
2020-04-09 23:46:54 +00:00
|
|
|
[service definition](/docs/agent/services). However, this approach registers
|
2015-02-28 00:00:13 +00:00
|
|
|
the local node as the service provider. In the case of external services, we must
|
|
|
|
instead register the service with the catalog rather than as part of a standard
|
|
|
|
node service definition.
|
|
|
|
|
|
|
|
Once registered, the DNS interface will be able to return the appropriate A
|
|
|
|
records or CNAME records for the service. The service will also appear in standard
|
2020-04-06 20:27:35 +00:00
|
|
|
queries against the API. Consul must be configured with a list of
|
2020-04-09 23:46:54 +00:00
|
|
|
[recursors](/docs/agent/options#recursors) for it to be able to resolve
|
2017-08-09 16:13:30 +00:00
|
|
|
external service addresses.
|
2014-02-25 20:22:25 +00:00
|
|
|
|
|
|
|
Let us suppose we want to register a "search" service that is provided by
|
2015-02-28 00:00:13 +00:00
|
|
|
"www.google.com". We might accomplish that like so:
|
2014-02-25 20:22:25 +00:00
|
|
|
|
2014-10-19 23:40:10 +00:00
|
|
|
```text
|
2015-02-28 00:00:13 +00:00
|
|
|
$ curl -X PUT -d '{"Datacenter": "dc1", "Node": "google",
|
|
|
|
"Address": "www.google.com",
|
|
|
|
"Service": {"Service": "search", "Port": 80}}'
|
|
|
|
http://127.0.0.1:8500/v1/catalog/register
|
2014-10-19 23:40:10 +00:00
|
|
|
```
|
2014-02-25 20:22:25 +00:00
|
|
|
|
2017-08-09 16:13:30 +00:00
|
|
|
Add an upstream DNS server to the list of recursors to Consul's configuration. Example with Google's public DNS server:
|
2020-04-06 20:27:35 +00:00
|
|
|
|
2017-08-09 16:13:30 +00:00
|
|
|
```text
|
|
|
|
"recursors":["8.8.8.8"]
|
|
|
|
```
|
|
|
|
|
2014-02-25 20:22:25 +00:00
|
|
|
If we do a DNS lookup now, we can see the new search service:
|
|
|
|
|
2014-10-19 23:40:10 +00:00
|
|
|
```text
|
|
|
|
; <<>> DiG 9.8.3-P1 <<>> @127.0.0.1 -p 8600 search.service.consul.
|
|
|
|
; (1 server found)
|
|
|
|
;; global options: +cmd
|
|
|
|
;; Got answer:
|
|
|
|
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 13313
|
|
|
|
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 0
|
|
|
|
|
|
|
|
;; QUESTION SECTION:
|
|
|
|
;search.service.consul. IN A
|
|
|
|
|
|
|
|
;; ANSWER SECTION:
|
|
|
|
search.service.consul. 0 IN CNAME www.google.com.
|
|
|
|
www.google.com. 264 IN A 74.125.239.114
|
|
|
|
www.google.com. 264 IN A 74.125.239.115
|
|
|
|
www.google.com. 264 IN A 74.125.239.116
|
|
|
|
|
|
|
|
;; Query time: 41 msec
|
|
|
|
;; SERVER: 127.0.0.1#8600(127.0.0.1)
|
|
|
|
;; WHEN: Tue Feb 25 17:45:12 2014
|
|
|
|
;; MSG SIZE rcvd: 178
|
|
|
|
```
|
2014-02-25 20:22:25 +00:00
|
|
|
|
2015-02-28 00:00:13 +00:00
|
|
|
If at any time we want to deregister the service, we simply do:
|
2014-02-25 20:22:25 +00:00
|
|
|
|
2014-10-19 23:40:10 +00:00
|
|
|
```text
|
|
|
|
$ curl -X PUT -d '{"Datacenter": "dc1", "Node": "google"}' http://127.0.0.1:8500/v1/catalog/deregister
|
|
|
|
```
|
2014-02-25 20:22:25 +00:00
|
|
|
|
2015-02-28 00:00:13 +00:00
|
|
|
This will deregister the `google` node along with all services it provides.
|
|
|
|
|
2020-04-09 23:46:54 +00:00
|
|
|
For more information, please see the [HTTP Catalog API](/api/catalog).
|