Communication between different jobs with Consul Connect

Hi!

Can tasks in different jobs communicate with each other and is that possible using Consul Connect?

According to the Consul Connect page Connect can be used to communicate between jobs. However, in the Connect integration example it implies it only works between tasks in the same job (as I understand it).

I tried splitting the tasks in the Consul integration example into different jobs but then the services cannot communicate with each other.

Thankful for advice.

1 Like

Howdy, @johanbook :wave:

I split up the jobs locally and ran them in my cluster and they connected correctly. I’ll attach the jobs here for your reference.

api.nomad
job "count-api" {
  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:v3"
      }
    }
  }
}
dashboard.nomad
job "count-dashboard" {
  datacenters = ["dc1"]

  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:v3"
      }
    }
  }
}

I was able to:

  • Run the dashboard.nomad job
  • Connect to the dashboard application using the address information from the allocation’s status
  • Observe the “Counting Service is Unreachable” error message
  • Run the api.nomad job
  • See the dashboard transition to “Connected”.

If this doesn’t get you sorted out, I’d be interested in your configurations and to see if you are getting errors in your Nomad and Consul logs.

Best,
Charlie V.

3 Likes

Thank you very much for you response. I got it working with your example.

Some follow up questions;

  • Have I understood this correctly;static = 9002 exposes a port on the host machine, to = 9002 states that incoming traffic should be routed to port 9002 in application. The service port = 9002 informs that the service accepts traffic on this port which then is forwarded to port = 9002?
  • How would one define multiple upstreams?
  • Can one create an upstream to the nomad api to submit job via a service?