2019-09-05 18:08:31 +00:00
|
|
|
---
|
2020-02-06 23:45:31 +00:00
|
|
|
layout: docs
|
|
|
|
page_title: connect Stanza - Job Specification
|
|
|
|
sidebar_title: connect
|
|
|
|
description: The "connect" stanza allows specifying options for Consul Connect integration
|
2019-09-05 18:08:31 +00:00
|
|
|
---
|
|
|
|
|
|
|
|
# `connect` Stanza
|
|
|
|
|
2020-02-06 23:45:31 +00:00
|
|
|
<Placement groups={['job', 'group', 'service', 'connect']} />
|
2019-09-05 18:08:31 +00:00
|
|
|
|
|
|
|
The `connect` stanza allows configuring various options for
|
2020-03-20 21:00:59 +00:00
|
|
|
[Consul Connect](/docs/integrations/consul-connect). It is
|
2019-09-05 18:08:31 +00:00
|
|
|
valid only within the context of a service definition at the task group
|
2020-05-07 19:53:22 +00:00
|
|
|
level. For using `connect` when Consul ACLs are enabled, be sure to read through
|
|
|
|
the [Secure Nomad Jobs with Consul Connect](https://learn.hashicorp.com/nomad/consul-integration/nomad-connect-acl)
|
|
|
|
guide.
|
2019-09-05 18:08:31 +00:00
|
|
|
|
|
|
|
```hcl
|
2020-05-07 19:38:29 +00:00
|
|
|
job "countdash" {
|
|
|
|
datacenters = ["dc1"]
|
|
|
|
|
|
|
|
group "api" {
|
|
|
|
network {
|
|
|
|
mode = "bridge"
|
|
|
|
}
|
|
|
|
|
|
|
|
service {
|
|
|
|
name = "count-api"
|
|
|
|
port = "9001"
|
|
|
|
|
|
|
|
connect {
|
|
|
|
sidecar_service {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
task "web" {
|
|
|
|
driver = "docker"
|
|
|
|
|
|
|
|
config {
|
|
|
|
image = "hashicorpnomad/counter-api:v2"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-09-05 18:08:31 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
## `connect` Parameters
|
|
|
|
|
2020-05-13 20:15:55 +00:00
|
|
|
- `native` - `(string: "")` - If non-empty, this indicates the task represented
|
|
|
|
by this service, for use with [Connect Native](https://www.consul.io/docs/connect/native)
|
|
|
|
applications. Incompatible with `sidecar_service` and `sidecar_task`.
|
|
|
|
|
2019-09-05 18:08:31 +00:00
|
|
|
- `sidecar_service` - <code>([sidecar_service][]: nil)</code> - This is used to configure the sidecar
|
2020-05-13 20:15:55 +00:00
|
|
|
service injected by Nomad for Consul Connect. Incompatible with `native`.
|
2019-09-05 18:08:31 +00:00
|
|
|
|
|
|
|
- `sidecar_task` - <code>([sidecar_task][]:nil)</code> - This modifies the configuration of the Envoy
|
2020-05-13 20:15:55 +00:00
|
|
|
proxy task. Incompatible with `native`.
|
2019-09-05 18:08:31 +00:00
|
|
|
|
|
|
|
## `connect` Examples
|
|
|
|
|
2020-05-13 20:15:55 +00:00
|
|
|
### Using Sidecar Service
|
|
|
|
|
2019-09-06 05:52:11 +00:00
|
|
|
The following example is a minimal connect stanza with defaults and is
|
|
|
|
sufficient to start an Envoy proxy sidecar for allowing incoming connections
|
|
|
|
via Consul Connect.
|
2019-09-05 18:08:31 +00:00
|
|
|
|
|
|
|
```hcl
|
|
|
|
connect {
|
|
|
|
sidecar_service {}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2019-09-06 05:52:11 +00:00
|
|
|
The following example includes specifying [`upstreams`][upstreams].
|
2019-09-05 18:08:31 +00:00
|
|
|
|
|
|
|
```hcl
|
|
|
|
connect {
|
|
|
|
sidecar_service {
|
|
|
|
proxy {
|
|
|
|
upstreams {
|
|
|
|
destination_name = "count-api"
|
|
|
|
local_bind_port = 8080
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-02-06 23:45:31 +00:00
|
|
|
```
|
2019-09-05 18:08:31 +00:00
|
|
|
|
2020-05-07 20:00:00 +00:00
|
|
|
The following is the complete `countdash` example. It includes an API service
|
2020-05-07 19:38:29 +00:00
|
|
|
and a frontend Dashboard service which connects to the API service as a Connect
|
|
|
|
upstream. Once running, the dashboard is accessible at `localhost:9002`.
|
|
|
|
|
|
|
|
```hcl
|
|
|
|
job "countdash" {
|
|
|
|
datacenters = ["dc1"]
|
|
|
|
|
|
|
|
group "api" {
|
|
|
|
network {
|
|
|
|
mode = "bridge"
|
|
|
|
}
|
|
|
|
|
|
|
|
service {
|
|
|
|
name = "count-api"
|
|
|
|
port = "9001"
|
|
|
|
|
|
|
|
connect {
|
|
|
|
sidecar_service {}
|
|
|
|
}
|
|
|
|
|
|
|
|
check {
|
|
|
|
expose = true
|
|
|
|
type = "http"
|
|
|
|
name = "api-health"
|
|
|
|
path = "/health"
|
|
|
|
interval = "10s"
|
|
|
|
timeout = "3s"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
task "web" {
|
|
|
|
driver = "docker"
|
|
|
|
|
|
|
|
config {
|
|
|
|
image = "hashicorpnomad/counter-api:v2"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
group "dashboard" {
|
|
|
|
network {
|
|
|
|
mode = "bridge"
|
|
|
|
|
|
|
|
port "http" {
|
|
|
|
static = 9002
|
|
|
|
to = 9002
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
service {
|
|
|
|
name = "count-dashboard"
|
|
|
|
port = "9002"
|
|
|
|
|
|
|
|
connect {
|
|
|
|
sidecar_service {
|
|
|
|
proxy {
|
|
|
|
upstreams {
|
|
|
|
destination_name = "count-api"
|
|
|
|
local_bind_port = 8080
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
task "dashboard" {
|
|
|
|
driver = "docker"
|
|
|
|
|
|
|
|
env {
|
|
|
|
COUNTING_SERVICE_URL = "http://${NOMAD_UPSTREAM_ADDR_count_api}"
|
|
|
|
}
|
|
|
|
|
|
|
|
config {
|
|
|
|
image = "hashicorpnomad/counter-dashboard:v2"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2020-05-13 20:15:55 +00:00
|
|
|
### Using Connect Native
|
|
|
|
|
|
|
|
The following example is a minimal connect stanza for a
|
|
|
|
[Consul Connect Native](https://www.consul.io/docs/connect/native)
|
|
|
|
application with task name `myTask`.
|
|
|
|
|
|
|
|
```hcl
|
|
|
|
connect {
|
|
|
|
native = "myTask"
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2019-09-06 05:52:11 +00:00
|
|
|
### Limitations
|
2019-09-05 18:08:31 +00:00
|
|
|
|
2020-05-13 20:15:55 +00:00
|
|
|
[Nomad variable interpolation][interpolation] is _not_ yet supported.
|
2020-02-06 23:45:31 +00:00
|
|
|
|
|
|
|
[job]: /docs/job-specification/job 'Nomad job Job Specification'
|
|
|
|
[group]: /docs/job-specification/group 'Nomad group Job Specification'
|
|
|
|
[task]: /docs/job-specification/task 'Nomad task Job Specification'
|
|
|
|
[interpolation]: /docs/runtime/interpolation 'Nomad interpolation'
|
|
|
|
[sidecar_service]: /docs/job-specification/sidecar_service 'Nomad sidecar service Specification'
|
|
|
|
[sidecar_task]: /docs/job-specification/sidecar_task 'Nomad sidecar task config Specification'
|
|
|
|
[upstreams]: /docs/job-specification/upstreams 'Nomad sidecar service upstreams Specification'
|
2019-09-06 05:52:11 +00:00
|
|
|
[native]: https://www.consul.io/docs/connect/native.html
|