In case anyone finds this useful I found a solution to this (although, I have not tested this across our cluster yet, single node only) by following the advice here https://github.com/hashicorp/nomad/issues/7229#issuecomment-649418198.
The change to the second example above is to also set the value of local_service_port on the service side car proxy to the same value as the to
port (9001 in this case).
job "countdash" {
datacenters = ["dc1"]
group "api" {
network {
mode = "bridge"
port "port_api" { to = 9001 }
}
service {
name = "count-api"
port = "port_api"
connect {
sidecar_service {
proxy {
local_service_port = 9001
}
}
}
}
task "web" {
driver = "docker"
config {
image = "hashicorpnomad/counter-api:v1"
ports = ["port_api"]
}
}
}
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 = 8085
}
}
}
}
}
task "dashboard" {
driver = "docker"
env {
COUNTING_SERVICE_URL = "http://${NOMAD_UPSTREAM_ADDR_count_api}"
}
config {
image = "hashicorpnomad/counter-dashboard:v1"
}
}
}
}