2016-11-01 12:53:13 +00:00
|
|
|
---
|
2020-02-06 23:45:31 +00:00
|
|
|
layout: docs
|
|
|
|
page_title: consul Stanza - Agent Configuration
|
|
|
|
sidebar_title: consul
|
2016-11-01 12:53:13 +00:00
|
|
|
description: |-
|
|
|
|
The "consul" stanza configures the Nomad agent's communication with
|
|
|
|
Consul for service discovery and key-value integration. When
|
|
|
|
configured, tasks can register themselves with Consul, and the Nomad cluster
|
|
|
|
can automatically bootstrap itself.
|
|
|
|
---
|
|
|
|
|
|
|
|
# `consul` Stanza
|
|
|
|
|
2020-02-06 23:45:31 +00:00
|
|
|
<Placement groups={['consul']} />
|
2016-11-01 12:53:13 +00:00
|
|
|
|
|
|
|
The `consul` stanza configures the Nomad agent's communication with
|
|
|
|
[Consul][consul] for service discovery and key-value integration. When
|
|
|
|
configured, tasks can register themselves with Consul, and the Nomad cluster can
|
|
|
|
[automatically bootstrap][bootstrap] itself.
|
|
|
|
|
|
|
|
```hcl
|
|
|
|
consul {
|
|
|
|
address = "127.0.0.1:8500"
|
|
|
|
auth = "admin:password"
|
|
|
|
token = "abcd1234"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
A default `consul` stanza is automatically merged with all Nomad agent
|
|
|
|
configurations. These sane defaults automatically enable Consul integration if
|
|
|
|
Consul is detected on the system. This allows for seamless bootstrapping of the
|
|
|
|
cluster with zero configuration. To put it another way: if you have a Consul
|
|
|
|
agent running on the same host as the Nomad agent with the default
|
|
|
|
configuration, Nomad will automatically connect and configure with Consul.
|
|
|
|
|
2020-01-08 18:08:54 +00:00
|
|
|
~> An important requirement is that each Nomad agent talks to a unique Consul
|
2018-05-11 13:47:04 +00:00
|
|
|
agent. Nomad agents should be configured to talk to Consul agents and not
|
2020-02-06 23:45:31 +00:00
|
|
|
Consul servers. If you are observing flapping services, you may have
|
2018-05-11 13:47:04 +00:00
|
|
|
multiple Nomad agents talking to the same Consul agent. As such avoid
|
|
|
|
configuring Nomad to talk to Consul via DNS such as consul.service.consul
|
|
|
|
|
2016-11-01 12:53:13 +00:00
|
|
|
## `consul` Parameters
|
|
|
|
|
|
|
|
- `address` `(string: "127.0.0.1:8500")` - Specifies the address to the local
|
2017-05-06 00:08:51 +00:00
|
|
|
Consul agent, given in the format `host:port`. Supports Unix sockets with the
|
2019-08-27 18:34:48 +00:00
|
|
|
format: `unix:///tmp/consul/consul.sock`. Will default to the
|
|
|
|
`CONSUL_HTTP_ADDR` environment variable if set.
|
2016-11-01 12:53:13 +00:00
|
|
|
|
2019-11-18 21:05:06 +00:00
|
|
|
- `allow_unauthenticated` `(bool: true)` - Specifies if users submitting jobs to
|
|
|
|
the Nomad server should be required to provide their own Consul token, proving
|
|
|
|
they have access to the service identity policies required by the Consul Connect
|
|
|
|
enabled services listed in the job. This option should be
|
|
|
|
disabled in an untrusted environment.
|
|
|
|
|
2016-11-01 12:53:13 +00:00
|
|
|
- `auth` `(string: "")` - Specifies the HTTP Basic Authentication information to
|
|
|
|
use for access to the Consul Agent, given in the format `username:password`.
|
|
|
|
|
|
|
|
- `auto_advertise` `(bool: true)` - Specifies if Nomad should advertise its
|
|
|
|
services in Consul. The services are named according to `server_service_name`
|
|
|
|
and `client_service_name`. Nomad servers and clients advertise their
|
|
|
|
respective services, each tagged appropriately with either `http` or `rpc`
|
|
|
|
tag. Nomad servers also advertise a `serf` tagged service.
|
|
|
|
|
|
|
|
- `ca_file` `(string: "")` - Specifies an optional path to the CA certificate
|
|
|
|
used for Consul communication. This defaults to the system bundle if
|
2019-08-27 18:34:48 +00:00
|
|
|
unspecified. Will default to the `CONSUL_CACERT` environment variable if set.
|
2016-11-01 12:53:13 +00:00
|
|
|
|
|
|
|
- `cert_file` `(string: "")` - Specifies the path to the certificate used for
|
|
|
|
Consul communication. If this is set then you need to also set `key_file`.
|
|
|
|
|
2017-09-21 09:06:39 +00:00
|
|
|
- `checks_use_advertise` `(bool: false)` - Specifies if Consul health checks
|
2016-11-01 12:53:13 +00:00
|
|
|
should bind to the advertise address. By default, this is the bind address.
|
|
|
|
|
|
|
|
- `client_auto_join` `(bool: true)` - Specifies if the Nomad clients should
|
|
|
|
automatically discover servers in the same region by searching for the Consul
|
|
|
|
service name defined in the `server_service_name` option. The search occurs if
|
|
|
|
the client is not registered with any servers or it is unable to heartbeat to
|
|
|
|
the leader of the region, in which case it may be partitioned and searches for
|
|
|
|
other servers.
|
|
|
|
|
|
|
|
- `client_service_name` `(string: "nomad-client")` - Specifies the name of the
|
|
|
|
service in Consul for the Nomad clients.
|
|
|
|
|
2018-03-21 07:28:07 +00:00
|
|
|
- `client_http_check_name` `(string: "Nomad Client HTTP Check")` - Specifies the
|
|
|
|
HTTP health check name in Consul for the Nomad clients.
|
|
|
|
|
2016-11-01 12:53:13 +00:00
|
|
|
- `key_file` `(string: "")` - Specifies the path to the private key used for
|
|
|
|
Consul communication. If this is set then you need to also set `cert_file`.
|
|
|
|
|
|
|
|
- `server_service_name` `(string: "nomad")` - Specifies the name of the service
|
|
|
|
in Consul for the Nomad servers.
|
|
|
|
|
2018-03-21 07:28:07 +00:00
|
|
|
- `server_http_check_name` `(string: "Nomad Server HTTP Check")` - Specifies the
|
|
|
|
HTTP health check name in Consul for the Nomad servers.
|
|
|
|
|
2020-02-06 23:45:31 +00:00
|
|
|
- `server_serf_check_name` `(string: "Nomad Server Serf Check")` - Specifies
|
2018-03-21 07:28:07 +00:00
|
|
|
the Serf health check name in Consul for the Nomad servers.
|
|
|
|
|
2020-02-06 23:45:31 +00:00
|
|
|
- `server_rpc_check_name` `(string: "Nomad Server RPC Check")` - Specifies
|
2018-03-21 07:28:07 +00:00
|
|
|
the RPC health check name in Consul for the Nomad servers.
|
|
|
|
|
2016-11-01 12:53:13 +00:00
|
|
|
- `server_auto_join` `(bool: true)` - Specifies if the Nomad servers should
|
|
|
|
automatically discover and join other Nomad servers by searching for the
|
|
|
|
Consul service name defined in the `server_service_name` option. This search
|
|
|
|
only happens if the server does not have a leader.
|
|
|
|
|
2020-05-13 20:15:55 +00:00
|
|
|
- `share_ssl` `(bool: true)` - Specifies whether the Nomad client should share
|
|
|
|
its Consul SSL configuration with Connect Native applications. Includes values
|
2020-06-24 15:13:22 +00:00
|
|
|
of `ca_file`, `cert_file`, `key_file`, `ssl`, and `verify_ssl`. Does not include
|
|
|
|
the values for the ACL `token` or `auth`. This option should be disabled in
|
|
|
|
environments where Consul ACLs are not enabled.
|
2020-05-13 20:15:55 +00:00
|
|
|
|
2016-11-01 12:53:13 +00:00
|
|
|
- `ssl` `(bool: false)` - Specifies if the transport scheme should use HTTPS to
|
2019-08-27 18:34:48 +00:00
|
|
|
communicate with the Consul agent. Will default to the `CONSUL_HTTP_SSL`
|
|
|
|
environment variable if set.
|
2016-11-01 12:53:13 +00:00
|
|
|
|
2019-05-14 18:37:34 +00:00
|
|
|
- `tags` `(array<string>: [])` - Specifies optional Consul tags to be
|
2019-01-09 20:38:39 +00:00
|
|
|
registered with the Nomad server and agent services.
|
|
|
|
|
2016-11-01 12:53:13 +00:00
|
|
|
- `token` `(string: "")` - Specifies the token used to provide a per-request ACL
|
2020-02-06 23:45:31 +00:00
|
|
|
token. This option overrides the Consul Agent's default token. If the token is
|
|
|
|
not set here or on the Consul agent, it will default to Consul's anonymous policy,
|
2018-05-24 18:47:32 +00:00
|
|
|
which may or may not allow writes.
|
2016-11-01 12:53:13 +00:00
|
|
|
|
|
|
|
- `verify_ssl` `(bool: true)`- Specifies if SSL peer verification should be used
|
2019-08-27 18:34:48 +00:00
|
|
|
when communicating to the Consul API client over HTTPS. Will default to the
|
|
|
|
`CONSUL_HTTP_SSL_VERIFY` environment variable if set.
|
|
|
|
|
2016-11-01 12:53:13 +00:00
|
|
|
If the local Consul agent is configured and accessible by the Nomad agents, the
|
|
|
|
Nomad cluster will [automatically bootstrap][bootstrap] provided
|
|
|
|
`server_auto_join`, `client_auto_join`, and `auto_advertise` are all enabled
|
|
|
|
(which is the default).
|
|
|
|
|
|
|
|
## `consul` Examples
|
|
|
|
|
|
|
|
### Default
|
|
|
|
|
|
|
|
This example shows the default Consul integration:
|
|
|
|
|
|
|
|
```hcl
|
2018-01-16 23:56:02 +00:00
|
|
|
consul {
|
|
|
|
address = "127.0.0.1:8500"
|
|
|
|
server_service_name = "nomad"
|
|
|
|
client_service_name = "nomad-client"
|
|
|
|
auto_advertise = true
|
|
|
|
server_auto_join = true
|
|
|
|
client_auto_join = true
|
|
|
|
}
|
2016-11-01 12:53:13 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
### Custom Address and Port
|
|
|
|
|
2020-03-12 22:05:34 +00:00
|
|
|
This example shows pointing the Nomad agent at a different Consul address. Note
|
|
|
|
that you should **never** point directly at a Consul server; always point to a
|
|
|
|
local client. In this example, the Consul server is bound and listening on the
|
2016-11-01 12:53:13 +00:00
|
|
|
node's private IP address instead of localhost, so we use that:
|
|
|
|
|
|
|
|
```hcl
|
|
|
|
consul {
|
|
|
|
address = "10.0.2.4:8500"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### Custom SSL
|
|
|
|
|
|
|
|
This example shows configuring custom SSL certificates to communicate with
|
|
|
|
the Consul agent. The Consul agent should be configured to accept certificates
|
|
|
|
similarly, but that is not discussed here:
|
|
|
|
|
|
|
|
```hcl
|
|
|
|
consul {
|
|
|
|
ssl = true
|
|
|
|
ca_file = "/var/ssl/bundle/ca.bundle"
|
2018-02-14 00:50:18 +00:00
|
|
|
cert_file = "/etc/ssl/consul.crt"
|
2016-11-01 12:53:13 +00:00
|
|
|
key_file = "/etc/ssl/consul.key"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2020-02-06 23:45:31 +00:00
|
|
|
[consul]: https://www.consul.io/ 'Consul by HashiCorp'
|
2020-03-20 21:00:59 +00:00
|
|
|
[bootstrap]: https://learn.hashicorp.com/nomad/operating-nomad/clustering 'Automatic Bootstrapping'
|