What is the 'nomad' way of doing route based reverse proxy to tasks/services

Hey!
I have this application with 3 parts:

Nomad is configured to bring up the service ‘batman’ with 3 tasks, as described above (each is packaged as a container, so I am using the docker driver). I could have made 3 services as well, but I didn’t :slight_smile:

This is the setup I have: internet - caddy - consul & nomad
consul-template is creating caddy configuration for automatic “ingress” (e.g. routing ‘the internet’ to the ‘batman’ service on app.example.com).

Now, my question is how to properly do reverse-proxying within the service?

  • simple solution is to create another task running nginx with proxy_pass and rewrite rules, but I think this is not the right way to go (this is how I’d do it with docker-compose)
  • I could go with fabio as described here, but I don’t know how this can run more than 1 such app, and I suppose I don’t want a system level service on each client for each app I am deploying…and I suppose I should change my consul-template to only fetch fabios then?
  • there is this service router available in consul, but I have no idea how to configure it through nomad

I’ll paste a simplified config that I currently have here, and I hope I can get some suggestions how to make it run! :smiley:

job "batman-dev" {
  datacenters = ["dc1"]
  type = "service"

  group "web" {
    count = 1
    network {
      mode = "bridge"
      port "application" {}
    }

    service {
      name = "batman"
      tags = ["public", "development"]
      port = "application"

      connect {
        sidecar_service {
          proxy {
            config {
             # I SUPPOSE I SHOULD DO SOMETHING HERE??
          }
        }      
      }
    }

    task "server" {
      driver = "docker"
      config {
        image = "api:nomad"
        ports = ["http"]
      }
    }

    task "admin" {
      driver = "docker"
      config {
        image = "ui:nomad"
        ports = ["http"]
      }
    } 

    task "player" {
      driver = "docker"
      config {
        image = "player:nomad"
        ports = ["http"]
      }
    }
  }
}

1 Like