Phew…glad it’s working now.
Yes, I will check with the rest of the team on what’s the best way to get this tutorial to work on other platforms. I just waiting to hear back from you and make sure that this was the problem .
Ah sorry, I forgot to check Traefik.
The first problem I see is that the job file is missing the port assignment to the task (I’ll make sure this gets fixed as well).
To deal with the Docker network issue, the first thing is that the Traefik container needs to be able to reach Consul. Normally the Consul agent would be available at 127.0.0.1:8500
of the host network, but that won’t work here.
So with these changes to traefik.nomad
you should be able to get it running and healthy:
job "traefik" {
# ...
group "traefik" {
# ...
task "traefik" {
driver = "docker"
config {
image = "traefik:v2.2"
- network_mode = "host"
+ ports = ["api", "http"]
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"
+ address = "host.docker.internal:8500"
scheme = "http"
EOF
destination = "local/traefik.toml"
}
# ...
}
}
}
The other part of the problem is that, since Nomad doesn’t know about this extra Docker network, the IP it will fingerprint for the client and store in the Consul catalog will not work from within a container.
I think there are two options here:
- Don’t use the Consul catalog for now, but rather render to a file and use the file provider. This would look like the Nginx example, and your
template
block would look like this:
job "traefik" {
# ...
group "traefik" {
# ...
task "traefik" {
# ...
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"
+ [providers]
+ [providers.file]
+ directory = "/etc/traefik"
+
+ [http]
+ [http.routers]
+ [http.routers.http]
+ rule = "Path(`/myapp`)"
+ service = "demo-webapp"
+
+ [http.services]
+ [http.services.demo-webapp.loadBalancer]
+
+ {{ range service "demo-webapp" }}
+ [[http.services.demo-webapp.loadBalancer.servers]]
+ url = "http://host.docker.internal:{{ .Port }}/"
+ {{ end }}
EOF
destination = "local/traefik.toml"
}
# ...
}
}
}
To make it easier, I uploaded the final job that worked for me in this Gist traefik.nomad · GitHub
- Use a Linux VM. This would be a bit more work to setup, but it would better simulate a production environment where Docker runs natively. Without this Docker network in the middle everything actually works pretty seamlessly
The alive
check in the traefik.nomad
file tells Nomad if Traefik is healthy. So it doesn’t affect the Traefik configuration, but rather you will see the Traefik allocation in Nomad being restarted after the healthy_deadline
passes.