github.com/anth0d/nomad@v0.0.0-20221214183521-ae3a0a2cad06/website/content/docs/configuration/consul.mdx (about) 1 --- 2 layout: docs 3 page_title: consul Stanza - Agent Configuration 4 description: |- 5 The "consul" stanza configures the Nomad agent's communication with 6 Consul for service discovery and key-value integration. When 7 configured, tasks can register themselves with Consul, and the Nomad cluster 8 can automatically bootstrap itself. 9 --- 10 11 # `consul` Stanza 12 13 <Placement groups={['consul']} /> 14 15 The `consul` stanza configures the Nomad agent's communication with 16 [Consul][consul] for service discovery and key-value integration. When 17 configured, tasks can register themselves with Consul, and the Nomad cluster can 18 [automatically bootstrap][bootstrap] itself. 19 20 ```hcl 21 consul { 22 address = "127.0.0.1:8500" 23 auth = "admin:password" 24 token = "abcd1234" 25 } 26 ``` 27 28 A default `consul` stanza is automatically merged with all Nomad agent 29 configurations. These sane defaults automatically enable Consul integration if 30 Consul is detected on the system. This allows for seamless bootstrapping of the 31 cluster with zero configuration. To put it another way: if you have a Consul 32 agent running on the same host as the Nomad agent with the default 33 configuration, Nomad will automatically connect and configure with Consul. 34 35 ~> An important requirement is that each Nomad agent talks to a unique Consul 36 agent. Nomad agents should be configured to talk to Consul agents and not 37 Consul servers. If you are observing flapping services, you may have 38 multiple Nomad agents talking to the same Consul agent. As such avoid 39 configuring Nomad to talk to Consul via DNS such as consul.service.consul 40 41 ## `consul` Parameters 42 43 - `address` `(string: "127.0.0.1:8500")` - Specifies the address to the local 44 Consul agent, given in the format `host:port`. Supports Unix sockets with the 45 format: `unix:///tmp/consul/consul.sock`. Will default to the 46 `CONSUL_HTTP_ADDR` environment variable if set. 47 The value supports [go-sockaddr/template format][go-sockaddr/template]. 48 49 - `allow_unauthenticated` `(bool: true)` - Specifies if users submitting jobs to 50 the Nomad server should be required to provide their own Consul token, proving 51 they have access to the service identity policies required by the Consul Connect 52 enabled services listed in the job. This option should be 53 disabled in an untrusted environment. 54 55 - `auth` `(string: "")` - Specifies the HTTP Basic Authentication information to 56 use for access to the Consul Agent, given in the format `username:password`. 57 58 - `auto_advertise` `(bool: true)` - Specifies if Nomad should advertise its 59 services in Consul. The services are named according to `server_service_name` 60 and `client_service_name`. Nomad servers and clients advertise their 61 respective services, each tagged appropriately with either `http` or `rpc` 62 tag. Nomad servers also advertise a `serf` tagged service. 63 64 - `ca_file` `(string: "")` - Specifies an optional path to the CA certificate 65 used for Consul communication. This defaults to the system bundle if 66 unspecified. Will default to the `CONSUL_CACERT` environment variable if set. 67 68 - `cert_file` `(string: "")` - Specifies the path to the certificate used for 69 Consul communication. If this is set then you need to also set `key_file`. 70 71 - `checks_use_advertise` `(bool: false)` - Specifies if Consul health checks 72 should bind to the advertise address. By default, this is the first [HTTP 73 address](https://www.nomadproject.io/docs/configuration#http). If no 74 [HTTP address](https://www.nomadproject.io/docs/configuration#http) is 75 specified, it will fall back to the 76 [bind_addr](https://www.nomadproject.io/docs/configuration#bind_addr). 77 78 - `client_auto_join` `(bool: true)` - Specifies if the Nomad clients should 79 automatically discover servers in the same region by searching for the Consul 80 service name defined in the `server_service_name` option. The search occurs if 81 the client is not registered with any servers or it is unable to heartbeat to 82 the leader of the region, in which case it may be partitioned and searches for 83 other servers. 84 85 - `client_service_name` `(string: "nomad-client")` - Specifies the name of the 86 service in Consul for the Nomad clients. 87 88 - `client_http_check_name` `(string: "Nomad Client HTTP Check")` - Specifies the 89 HTTP health check name in Consul for the Nomad clients. 90 91 - `grpc_address` `(string: "127.0.0.1:8502")` - Specifies the address to the local 92 Consul agent for `gRPC` requests, given in the format `host:port`. Note that 93 Consul does not enable the [`grpc`][grpc_port] or [`grpc_tls`][grpctls_port] 94 listeners by default. 95 96 - `key_file` `(string: "")` - Specifies the path to the private key used for 97 Consul communication. If this is set then you need to also set `cert_file`. 98 99 - `namespace` `(string: "")` - Specifies the [Consul namespace](https://developer.hashicorp.com/consul/docs/enterprise/namespaces) 100 used by the Consul integration. If non-empty, this namespace will be used on 101 all Consul API calls and for Consul Connect configurations. 102 103 - `server_service_name` `(string: "nomad")` - Specifies the name of the service 104 in Consul for the Nomad servers. 105 106 - `server_http_check_name` `(string: "Nomad Server HTTP Check")` - Specifies the 107 HTTP health check name in Consul for the Nomad servers. 108 109 - `server_serf_check_name` `(string: "Nomad Server Serf Check")` - Specifies 110 the Serf health check name in Consul for the Nomad servers. 111 112 - `server_rpc_check_name` `(string: "Nomad Server RPC Check")` - Specifies 113 the RPC health check name in Consul for the Nomad servers. 114 115 - `server_auto_join` `(bool: true)` - Specifies if the Nomad servers should 116 automatically discover and join other Nomad servers by searching for the 117 Consul service name defined in the `server_service_name` option. This search 118 only happens if the server does not have a leader. 119 120 - `share_ssl` `(bool: true)` - Specifies whether the Nomad client should share 121 its Consul SSL configuration with Connect Native applications. Includes values 122 of `ca_file`, `cert_file`, `key_file`, `ssl`, and `verify_ssl`. Does not include 123 the values for the ACL `token` or `auth`. This option should be disabled in 124 environments where Consul ACLs are not enabled. 125 126 - `ssl` `(bool: false)` - Specifies if the transport scheme should use HTTPS to 127 communicate with the Consul agent. Will default to the `CONSUL_HTTP_SSL` 128 environment variable if set. 129 130 - `tags` `(array<string>: [])` - Specifies optional Consul tags to be 131 registered with the Nomad server and agent services. 132 133 - `timeout` `(string: "5s")` - Specifies a time limit for requests made against 134 Consul. This is specified using a label suffix like "10s". 135 136 - `token` `(string: "")` - Specifies the token used to provide a per-request ACL 137 token. This option overrides the Consul Agent's default token. If the token is 138 not set here or on the Consul agent, it will default to Consul's anonymous policy, 139 which may or may not allow writes. 140 141 - `verify_ssl` `(bool: true)`- Specifies if SSL peer verification should be used 142 when communicating to the Consul API client over HTTPS. Will default to the 143 `CONSUL_HTTP_SSL_VERIFY` environment variable if set. 144 145 If the local Consul agent is configured and accessible by the Nomad agents, the 146 Nomad cluster will [automatically bootstrap][bootstrap] provided 147 `server_auto_join`, `client_auto_join`, and `auto_advertise` are all enabled 148 (which is the default). 149 150 ## `consul` Examples 151 152 ### Default 153 154 This example shows the default Consul integration: 155 156 ```hcl 157 consul { 158 address = "127.0.0.1:8500" 159 server_service_name = "nomad" 160 client_service_name = "nomad-client" 161 auto_advertise = true 162 server_auto_join = true 163 client_auto_join = true 164 } 165 ``` 166 167 ### Custom Address and Port 168 169 This example shows pointing the Nomad agent at a different Consul address. Note 170 that you should **never** point directly at a Consul server; always point to a 171 local client. In this example, the Consul server is bound and listening on the 172 node's private IP address instead of localhost, so we use that: 173 174 ```hcl 175 consul { 176 address = "10.0.2.4:8500" 177 } 178 ``` 179 180 ### Custom SSL 181 182 This example shows configuring custom SSL certificates to communicate with 183 the Consul agent. The Consul agent should be configured to accept certificates 184 similarly, but that is not discussed here: 185 186 ```hcl 187 consul { 188 ssl = true 189 ca_file = "/var/ssl/bundle/ca.bundle" 190 cert_file = "/etc/ssl/consul.crt" 191 key_file = "/etc/ssl/consul.key" 192 } 193 ``` 194 195 ### Consul Namespace 196 197 Consul does not allow ACL policies associated with namespaces to use agent 198 permissions. Nomad requires `agent:read` permissions. In order to use the 199 `consul_namespace` feature, Nomad will need a token generated in Consul's 200 default namespace. That token should be created with `agent:read` as well 201 as a `namespace` block with the other relevant permissions for running Nomad 202 in the intended namespace. The Consul policy below shows an example policy 203 configuration for a Nomad server: 204 205 ``` 206 agent_prefix "" { 207 policy = "read" 208 } 209 210 namespace "nomad-ns" { 211 acl = "write" 212 213 key_prefix "" { 214 policy = "read" 215 } 216 217 node_prefix "" { 218 policy = "read" 219 } 220 221 service_prefix "" { 222 policy = "write" 223 } 224 } 225 ``` 226 227 [consul]: https://www.consul.io/ 'Consul by HashiCorp' 228 [bootstrap]: https://learn.hashicorp.com/tutorials/nomad/clustering 'Automatic Bootstrapping' 229 [go-sockaddr/template]: https://pkg.go.dev/github.com/hashicorp/go-sockaddr/template 230 [grpc_port]: https://developer.hashicorp.com/consul/docs/agent/config/config-files#grpc_port 231 [grpctls_port]: https://developer.hashicorp.com/consul/docs/agent/config/config-files#grpc_tls_port