Traefik/consul provider connection error

I’m a bit new and I’m trying to follow this traefik, nomad, consul tutorial.

I seem to be able to follow all the steps and everything almost seems to work.

I’m able to run the demo web app and traefik jobs with nomad.

The demo web app doesn’t seem to have any problem registering with consul (see the screen shot below), but the traefik job can’t seem to connect to consul. I keep getting the folllowing error.

time="2020-12-31T16:25:02Z" level=info msg="Configuration loaded from file: /etc/traefik/traefik.toml"
time="2020-12-31T16:25:17Z" level=error msg="error get consul catalog data, Get \"http://127.0.0.1:8500/v1/catalog/services\": dial tcp 127.0.0.1:8500: connect: connection refused" providerName=consulcatalog
time="2020-12-31T16:25:17Z" level=error msg="Provider connection error Get \"http://127.0.0.1:8500/v1/catalog/services\": dial tcp 127.0.0.1:8500: connect: connection refused, retrying in 676.526777ms" providerName=consulcatalog
time="2020-12-31T16:25:32Z" level=error msg="error get consul catalog data, Get \"http://127.0.0.1:8500/v1/catalog/services\": dial tcp 127.0.0.1:8500: connect: connection refused" providerName=consulcatalog
time="2020-12-31T16:25:32Z" level=error msg="Provider connection error Get \"http://127.0.0.1:8500/v1/catalog/services\": dial tcp 127.0.0.1:8500: connect: connection refused, retrying in 502.970353ms" providerName=consulcatalog
time="2020-12-31T16:25:48Z" level=error msg="error get consul catalog data, Get \"http://127.0.0.1:8500/v1/catalog/services\": dial tcp 127.0.0.1:8500: connect: connection refused" providerName=consulcatalog
time="2020-12-31T16:25:48Z" level=error msg="Provider connection error Get \"http://127.0.0.1:8500/v1/catalog/services\": dial tcp 127.0.0.1:8500: connect: connection refused, retrying in 573.428123ms" providerName=consulcatalog

Since I’m kind of new and still following beginner tutorials, I’m having trouble pin-pointing the problem.

I’m currently running on a MacOs

Any help is much appreciated.

Hi @jeffreycwitt,

I believe there are a couple of issues why this is not working. The first is that Docker’s host networking mode only works on Linux, and is not available on macOS or Windows.

The host networking driver only works on Linux hosts, and is not supported on Docker Desktop for Mac, Docker Desktop for Windows, or Docker EE for Windows Server.

Source: Host network driver | Docker Docs

Second, I assume you’re running this on a recent version of Nomad (0.12.x or higher). The job file will not work as written on recent versions because the network block can no longer be placed under job -> group -> task -> resources (see Nomad 0.12: Task Network Resource deprecation).

The job file needs to be modified to move the network stanza to job -> group -> network. Correspondingly the service definition needs to be moved from under task to job -> group -> service in order for the service’s port label reference to be valid.

Here’s a modified job file for Traefik that I have verified works on Linux.

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

  group "traefik" {
    count = 1

    network {
      port "http" {
        static = 8080
      }

      port "api" {
        static = 8081
      }
    }

    task "traefik" {
      driver = "docker"

      config {
        image        = "traefik:v2.2"
        network_mode = "host"

        volumes = [
          "local/traefik.toml:/etc/traefik/traefik.toml",
        ]
      }

      template {
        data = <<EOF
[entryPoints]
    [entryPoints.http]
    address = ":8080"
    [entryPoints.traefik]
    address = ":8081"

[api]
    dashboard = true
    insecure  = true

# Enable Consul Catalog configuration backend.
[providers.consulCatalog]
    prefix           = "traefik"
    exposedByDefault = false

    [providers.consulCatalog.endpoint]
      address = "127.0.0.1:8500"
      scheme  = "http"
EOF

        destination = "local/traefik.toml"
      }

      resources {
        cpu    = 100
        memory = 128
      }

    }

    service {
      name = "traefik"

      check {
        name     = "alive"
        type     = "tcp"
        port     = "http"
        interval = "10s"
        timeout  = "2s"
      }
    }
  }
}

I hope this helps. I will see about getting the tutorial updated to reflect the OS limitation, and the configuration file changes.

2 Likes

Definitely helps. Thanks so much. At least I know I wasn’t doing something obviously wrong.

Just to be clear, at present even if I “update” the job file, following the current tutorial on my mac won’t work because the network mode = “host” is not supported on mac? And I should just wait until someone has a chance to update the tutorial for a mac workaround?

Meanwhile, I have access to a Redhat instance, so I’ll try to follow the tutorial again on that system. :slight_smile:

Yes, even if you update the job file it will not work on macOS since Docker’s host networking mode is not supported on that platform. The tutorial could be updated to deploy Traefik as an exec task in Nomad which should overcome this limitation.

You should have more success trying this on that Linux instance. :slight_smile:

2 Likes