Cannot deploy Nomad task with Traefik loadbalancing using Nomad's native service discovery

Hi all,

I was playing around with Traefik as reverse proxy for my Nomad cluster. I want to make use of Nomad its new service discovery functionalities as described here (Traefik Proxy Integrates with Hashicorp Nomad | Traefik Labs) to host my home-assistant container. So this setup is running without Consul (sorry, I could not select Nomad as tag only Consul)

The only problem is that I cannot get the Traefik routing to work. The Traefik task is defined as in the example

job "traefik" {
  datacenters = ["dc1"]
  type        = "service"

  group "traefik" {
    count = 1

    network {
      port  "http"{
         static = 80
         host_network = "wlan"
      }
      port  "admin"{
         static = 8080
         host_network = "wlan"
      }
    }

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

    task "server" {
      driver = "docker"
      config {
        image = "traefik:2.8"
        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.nomad=true",
          "--providers.nomad.endpoint.address=http://192.168.178.XX:4646" ### IP to your nomad server
        ]
      }
    }
  }
}

The home-assistant container is defined as follows


variable "homeassistant_password" {
 type    = string
}


job "home-assistant" {
  datacenters = ["dc1"]
  type        = "service"

  group "home-assistant" {
    count = 1

    network {
      port "http" {
        to     = 8123
        static = 8123
        host_network = "wlan"
      }

      port "http-tailscale" {
        to = 8123
        static = 8123
        host_network = "tailscale"
	}
    }

    volume "home-assistant-config" {
      type      = "host"
      read_only = false
      source    = "home-assistant-config"
    }

    task "home-assistant" {
      driver = "docker"

      volume_mount {
        volume      = "home-assistant-config"
        destination = "/config"
        read_only   = false
      }

      config {
        image = "ghcr.io/home-assistant/home-assistant:latest"
        ports = ["http", "http-tailscale"]
      }

      template {
        data = <<EOF
         {{- range nomadService "postgres" }}
  	  POSTGRES_URL=REDACTED{{- end }}
        EOF

        destination = "local/file.env"
        env         = true
      }

      service {
        name     = "home-assistant"
        port     = "http"
        provider = "nomad"

      tags = [
        "traefik.enable=true",
        "traefik.http.routers.http.rule=Path(`/ha`)",
      ]

      }
    }
  }
}

The problem is however that I dont see the HTTP Router picking this up in the dashboard. When I use Host() instead of Path() I do see the HTTP Router picking it up, but without me being able to resolve it. Can some more experienced Traefik users maybe give me some pointers here?

Setup: intel nuc running arch linux.

Thanks!

Have you tried latest Traefik v2.10? v2.8 seems a bit old.

Updated to 2.10, but the situation stays the same.

The error was related to the application I am hosting (home-assistant) you cannot host it on a path like /ha. Only on a subdomain.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.