hashicorp / hashicorp/nomad

Add interpolation for driver IP address of another task within the group

Open
#4,913 11 comments 11 reactions 0 assignees View on GitHub
stage/needs-discussion theme/networking type/enhancement
Dominant language
Go
Stars
17k
Forks
2.1k
Avg merge
1d 9h
Merged PRs (30d)
105

Description

### Nomad version
Nomad v0.8.6 (ab54ebcfcde062e9482558b7c052702d4cb8aa1b+CHANGES)

### Feature Request

There is currently no way to interpolate another task *driver* IP address within the same group. By driver IP address, I mean the IP address associated to the docker container within the docker network. The same address as advertised by [`address_mode = driver` within a service stanza](https://www.nomadproject.io/docs/job-specification/service.html#driver-1).

What would be nice is to be able to write `${NOMAD_DRIVER_IP_taskname}` and have it evaluate to the IP address of the container for the task `taskname`.

The primary use case for this would be to use consul-connect within nomad and have a fixed port number for the proxied service. Having a fixed port can be sometimes necessary when the service being run does not accept communicating on another port number than the standard one. For example, many DNS clients refuse to connect to DNS servers on other ports than port 53.

Example use-case nomad job:

```hcl
job "web" {
type = "service"

datacenters = ["dc1"]

group "main" {
task "main" {
driver = "docker"

config {
# The web service is hardcoded to connect to its database on database:5432
image = "web"

extra_hosts = [
"database:${NOMAD_DRIVER_IP_proxy}",
]

port_map {
http = 8080
}
}

resources {
cpu = 100
memory = 128
network {
mbits = 10
port "http" {}
}
}
}

task "proxy" {
driver = "docker"

config {
# here we have a connect proxy that listens on 8080 within the docker
# container for incoming requests for the web service, and it is also
# listening on port 5432 to proxy db requests coming from the web
# service.
image = "consul"
command = "consul"
args = [
"connect", "proxy",
"-service", "web",
"-upstream", "db:5432",
"-service-addr", "${NOMAD_ADDR_main_http}",
"-listen", ":8080",
"-register",
]
port_map {
web = 8080
db = 5432
}
}

resources {
network {
port "web" {}
port "db" {}
}
}
}
}
}
```

Contributor guide

No contributing guide indexed for this repository

Research direction

The issue does not name implementation files or tests. Start by tracing the existing NOMAD_ADDR_main_http interpolation and the driver address_mode behavior described in the service stanza; done means a variable such as NOMAD_DRIVER_IP_proxy resolves to the same container IP available through driver mode for another task in the group.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, go
Domain
devops, infrastructure
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.