Path routing doesn't work for a Nomad job

Hi I am using Nomad / Consul and Traefik stack.
I have provisiooned traefik stack using Nomad as service as seen below:

job "traefikv3" {
  datacenters = ["dc1"]
  type        = "system"

  group "traefik" {
    count = 1

    network {
      port  "http"{
         static = 80
      }
      port  "admin"{
         static = 8081
      }
    }

    service {
      name = "traefik-http"
      provider = "nomad"
      port = "http"
    }

    task "server" {
      driver = "docker"
      config {
        image = "registry.local/traefik:v2.9"
        network_mode = "host"
        ports = ["admin", "http"]
        args = [
          "--api.dashboard=true",
          "--api.insecure=true", ### For Test only, please do not use that in production
          "--entrypoints.web.address=:${NOMAD_PORT_http}",
          "--entrypoints.traefik.address=:${NOMAD_PORT_admin}",
          "--providers.consulcatalog=true",
          "--providers.consulcatalog.exposedByDefault=false",
          "--providers.consulcatalog.endpoint.address=http://<CONSUL ENDPOINT>:8500",
          "--providers.consulcatalog.prefix=traefik",
          "--providers.consulcatalog.defaultrule=Host(`traefik.local.com`)",
          "--log.filePath=/var/log/traefik//traefik.log",
          "--log.level=DEBUG"
        ]
      }
    }
  }
}

I see that traefik running on all my Nomad agent hosts as seen below and I can browse on each

I now created service in Nomad with a definition as seen below

job "email-handler-api" {
  datacenters = ["dc1"]

  group "api" {
     scaling {
      min     = 1
      max     = 10
      enabled = true
}
spread {
attribute = "${node.unique.id}"
}
    network {
      port  "http"{
        to = 80
      }
    }
    service {
      name = "emailhandler-api"
      port = "http"

      tags = [
        "traefik.enable=true",        
        "traefik.http.routers.http.rule=Path(`/emailhandler-api`)",
      ]
      check {
        type     = "http"
        path     = "/index.html"
        interval = "10s"
        timeout  = "5s"
      }
    }

    task "server" {
      env {
        PORT    = "${NOMAD_PORT_http}"
        NODE_IP = "${NOMAD_IP_http}"
        ASPNETCORE_ENVIRONMENT = "dev"
        HashiVaultRoleId_arch = "e94158b9-1709-3aeb-d08a-2c010871eecd"
      }

      driver = "docker"

      config {
        image = "registry.local/emailhandler.webapi:0.1.9"
        ports = ["http"]
        force_pull = true
      }
    }
  }
}

I see in consul that service is healthy.

I can directly browse the endpoint from the nomad agent IP and randomly assigned. port by IP and service is working just fine

Traefik also shows that service is registered fine

I then created a host entry for treafik.local.com for one of the traefik hosts.
When I try to browse http://traefik.local.com/emailhandler-api/ I get 404

Can someone please assist me with this issue?

Thanks a lot

Anyone.. Please help me with this issue. When I remove path, it works.. So I know for sure that there is nothing wrong with my Nomad, Consul or Traefik setup. It is just Path based routing is not working. I know I am missing a very little thing.. that I just can't figure out.

Your Path() will only accept /emailhandler-api but nothing else like /emailhandler-api/a1b2c3. Maybe try PathPrefix() instead.

@bluepuma77 , as you suggested, I made changes to the nomad job and replace Path with PathPrefix. Now I get 404 which even doesn't seem to be hitting Traefik at all. Here is the screenshot with PathPrefix:

Here is my new job definition

job "email-handler-api" {
  datacenters = ["dc1"]

  group "api" {
     scaling {
      min     = 1
      max     = 10
      enabled = true
}


spread {
attribute = "${node.unique.id}"
}
    network {
      port  "http"{
        to = 80
      }
    }
    service {
      name = "emailhandler-api"
      port = "http"

      tags = [
        "traefik.enable=true",        
        "traefik.http.routers.emailhandler-api.rule=PathPrefix(`/emailhandler-api`)"        
      ]
      check {
        type     = "http"
        path     = "/index.html"
        interval = "10s"
        timeout  = "5s"
      }
    }
    task "server" {
      env {
        PORT    = "${NOMAD_PORT_http}"
        NODE_IP = "${NOMAD_IP_http}"
        ASPNETCORE_ENVIRONMENT = "dev"        
      }
      driver = "docker"
      config {
        image = "registry.local/emailhandler.webapi:0.1.9"
        ports = ["http"]
        force_pull = true
      }
    }
  }
}

Here is a screenshot when Path was used earlier instead:

image

Hey Andy,

Were you able to figure this out? I am facing a similar issue now so wondering if there's a wor around.

thanks,
Vik

No. It didn't work for me. I moved on to HAProxy