Register service with a local IP address on a node

Hi folks,

I have multiple dynamic services running on a node and they have their own dynamic local IP addresses (for example 192.168.1.3). They are all reachable from the node’s host namespace but I also create new network namespaces for each service manually – can we propagate this information to Consul and use it for routing the request with some built-in Nomad features?

How would I register these services with Consul so I can route traffic to them from some central proxy?

1 Like

Hi @ValentaTomas,

Consul supports providing an optional address field in the service registration. If left empty, it defaults to the agent’s advertise address.

Here’s an example config.

# agent-config.hcl

services {
  name = "web"
  address = "192.0.2.10"
  port = 80
}

services {
  name = "db"
  address = "198.51.100.200"
  port = 3306
}

Nomad 1.3.0 introduced support for setting the address field in the service block of a job definition. See hashicorp/nomad#12720 for more info.

1 Like

Sounds great – can you use a local address there?

If I have a service with a local address running on a Nomad node that is accessible only through that local IP in the node’s host namespace can Consul route traffic to that local IP when I define the service stanza with the local address?