github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/website/content/docs/configuration/consul.mdx (about)

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