Merge pull request #6434 from hashicorp/docs-add-grpc-info

docs: Added grpc info; small style fixes to connect guide
This commit is contained in:
Charlie Voiselle 2019-10-16 14:18:20 -04:00 committed by GitHub
commit ae8bfce399
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 141 additions and 98 deletions

View File

@ -56,6 +56,40 @@ run in dev mode with the following command:
$ consul agent -dev $ consul agent -dev
``` ```
To use Connect on a non-dev Consul agent, you will minimally need to enable the
GRPC port and set `connect` to enabled by adding some additional information to
your Consul client configurations, depending on format.
For HCL configurations:
```hcl
# ...
ports {
"grpc" = 8502
}
connect {
enabled = true
}
```
For JSON configurations:
```javascript
{
// ...
"ports": {
"grpc": 8502
},
"connect": {
"enabled": true
}
}
```
### Nomad ### Nomad
Nomad must schedule onto a routable interface in order for the proxies to Nomad must schedule onto a routable interface in order for the proxies to
@ -87,66 +121,71 @@ to Nomad by copying the HCL into a file named `connect.nomad` and running:
`nomad run connect.nomad` `nomad run connect.nomad`
```hcl ```hcl
job "countdash" { job "countdash" {
datacenters = ["dc1"] datacenters = ["dc1"]
group "api" {
network {
mode = "bridge"
}
service { group "api" {
name = "count-api" network {
port = "9001" mode = "bridge"
}
connect { service {
sidecar_service {} name = "count-api"
} port = "9001"
}
task "web" { connect {
driver = "docker" sidecar_service {}
config { }
image = "hashicorpnomad/counter-api:v1" }
}
}
}
group "dashboard" { task "web" {
network { driver = "docker"
mode = "bridge"
port "http" {
static = 9002
to = 9002
}
}
service { config {
name = "count-dashboard" image = "hashicorpnomad/counter-api:v1"
port = "9002" }
}
}
connect { group "dashboard" {
sidecar_service { network {
proxy { mode = "bridge"
upstreams {
destination_name = "count-api"
local_bind_port = 8080
}
}
}
}
}
task "dashboard" { port "http" {
driver = "docker" static = 9002
env { to = 9002
COUNTING_SERVICE_URL = "http://${NOMAD_UPSTREAM_ADDR_count_api}" }
} }
config {
image = "hashicorpnomad/counter-dashboard:v1" 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:v1"
}
}
}
}
``` ```
The job contains two task groups: an API service and a web frontend. The job contains two task groups: an API service and a web frontend.
@ -156,33 +195,35 @@ The job contains two task groups: an API service and a web frontend.
The API service is defined as a task group with a bridge network: The API service is defined as a task group with a bridge network:
```hcl ```hcl
group "api" { group "api" {
network { network {
mode = "bridge" mode = "bridge"
} }
... # ...
} }
``` ```
Since the API service is only accessible via Consul Connect, it does not define Since the API service is only accessible via Consul Connect, it does not define
any ports in its network. The service stanza enables Connect: any ports in its network. The service stanza enables Connect:
```hcl ```hcl
group "api" { group "api" {
...
service { # ...
name = "count-api"
port = "9001"
connect { service {
sidecar_service {} name = "count-api"
} port = "9001"
}
... connect {
} sidecar_service {}
}
}
# ...
}
``` ```
The `port` in the service stanza is the port the API service listens on. The The `port` in the service stanza is the port the API service listens on. The
@ -195,17 +236,19 @@ The web frontend is defined as a task group with a bridge network and a static
forwarded port: forwarded port:
```hcl ```hcl
group "dashboard" { group "dashboard" {
network { network {
mode ="bridge" mode = "bridge"
port "http" {
static = 9002
to = 9002
}
}
... port "http" {
} static = 9002
to = 9002
}
}
# ...
}
``` ```
The `static = 9002` parameter requests the Nomad scheduler reserve port 9002 on The `static = 9002` parameter requests the Nomad scheduler reserve port 9002 on
@ -220,21 +263,21 @@ This allows you to connect to the web frontend in a browser by visiting
The web frontend connects to the API service via Consul Connect: The web frontend connects to the API service via Consul Connect:
```hcl ```hcl
service { service {
name = "count-dashboard" name = "count-dashboard"
port = "9002" port = "9002"
connect { connect {
sidecar_service { sidecar_service {
proxy { proxy {
upstreams { upstreams {
destination_name = "count-api" destination_name = "count-api"
local_bind_port = 8080 local_bind_port = 8080
} }
} }
} }
} }
} }
``` ```
The `upstreams` stanza defines the remote service to access (`count-api`) and The `upstreams` stanza defines the remote service to access (`count-api`) and
@ -244,9 +287,9 @@ The web frontend is configured to communicate with the API service with an
environment variable: environment variable:
```hcl ```hcl
env { env {
COUNTING_SERVICE_URL = "http://${NOMAD_UPSTREAM_ADDR_count_api}" COUNTING_SERVICE_URL = "http://${NOMAD_UPSTREAM_ADDR_count_api}"
} }
``` ```
The web frontend is configured via the `$COUNTING_SERVICE_URL`, so you must The web frontend is configured via the `$COUNTING_SERVICE_URL`, so you must
@ -261,7 +304,7 @@ dashes (`-`) are converted to underscores (`_`) in environment variables so
- Consul Connect Native is not yet supported. - Consul Connect Native is not yet supported.
- Consul Connect HTTP and gRPC checks are not yet supported. - Consul Connect HTTP and gRPC checks are not yet supported.
- Consul ACLs are not yet supported. - Consul ACLs are not yet supported.
- Only the Docker, exec, raw exec, and java drivers support network namespaces - Only the Docker, exec, raw_exec, and java drivers support network namespaces
and Connect. and Connect.
- Variable interpolation for group services and checks are not yet supported. - Variable interpolation for group services and checks are not yet supported.
- Consul Connect and network namespaces are only supported on Linux. - Consul Connect and network namespaces are only supported on Linux.