I'm trying to set up Traefik to run on Nomad with Consul but can't get the defaultRule to work. For any template value that I try I get "" even though for things like name the Traefik dashboard has the name from Consul. I'm also wondering what other values I can use than Name - everything I've tried like Domain also doesn't work but I couldn't find any docs on that.
Here's my config:
# Define entrypoints
[entryPoints]
[entryPoints.web]
address = ":9000"
[entryPoints.traefik]
address = ":9001"
# Enable Traefik API
[api]
dashboard = true
insecure = true
[http.routers.traefik]
service = "api@internal"
# Enable Consul Catalog Provider.
[providers.consulCatalog]
# Expose Consul catalog services by default in Traefik.
exposedByDefault = true
# Default rule for Consul services.
defaultRule = "Host(`{{ .Name }}`)"
#[tracing]
[accessLog]
[log]
level = "DEBUG"
Any idea what I'm doing wrong? Thanks for the help!
1 Like
I have the same issue, tried .ServiceName and .Name but can't find out why it's not working.
ldez
October 31, 2020, 9:57am
3
Hello,
currently, in CC provider you can use:
{{ .Name }}
that contains the ServiceName from CC (not related to tags or Traefik service)
{{ .Labels }}
that contains the tags used by Traefik.
if {{ .Name }}
is empty it's because CC returns an empty value for the ServiceName.
In Traefik UI i can see the service names. Also in the default rule, if I put {{ normalize .Name }} I have an exception normalize not found
ldez
October 31, 2020, 10:08am
6
When I talk about ServiceName
, I talk about the information from CC (not tags or labels), not related to Traefik.
normalize
is a common function available by default.
Could you provide your configuration?
In CC the service name is correct. My Traefik logs:
level=debug msg="Creating middleware" serviceName=plex middlewareName=pipelining middlewareType=Pipelining entryPointName=http routerName=plex@consulcatalog
time="2020-10-31T10:09:29Z" level=debug msg="Creating load-balancer" entryPointName=http routerName=plex@consulcatalog serviceName=plex
time="2020-10-31T10:09:29Z" level=debug msg="Creating server 0 http://192.168.1.201:32400" serviceName=plex entryPointName=http routerName=plex@consulcatalog serverName=0
time="2020-10-31T10:09:29Z" level=debug msg="Added outgoing tracing middleware plex" routerName=plex@consulcatalog middlewareName=tracing middlewareType=TracingForwarder entryPointName=http
I don't see any missing information and it's weird that if I use the same default rule:
This config fail to start with missing normalize function :
[providers.consulCatalog]
prefix = "traefik"
exposedByDefault = true
defaultRule=Host(`{{ normalize .Name }}`)
This will get <no value>
output
[providers.consulCatalog]
prefix = "traefik"
exposedByDefault = true
defaultRule = "Host(`{{ .Name }}.192.168.1.201.nip.io`)"
This one will expose with the default Host({{ .Name }}
) correctly
[providers.consulCatalog]
prefix = "traefik"
exposedByDefault = true
### removed default rule###
ldez
October 31, 2020, 10:26am
8
Could you provide your full configuration?
FYI, when you don't define an explicit defaultRule
traefik uses Host(`{{ normalize .Name }}`)
.
ldez
October 31, 2020, 10:30am
9
the quotes are missing around the defautRule
value.
[providers.consulCatalog]
prefix = "traefik"
exposedByDefault = true
defaultRule = "Host(`{{ normalize .Name }}`)"
That's my point! If i remove defaultRule it works. If I put the exact same default rule in defaultRule
it fails to start.
My full config (the missing quotes is not in this config. i didn't copy pasted last post)
[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.https]
address = ":443"
[entryPoints.traefik]
address = ":8081"
[api]
dashboard = true
insecure = true
# Enable Consul Catalog configuration backend.
[providers.consulCatalog]
prefix = "traefik"
exposedByDefault = true
defaultRule = "Host(`{{ .Name }}.192.168.1.201.nip.io`)"
[providers.consulCatalog.endpoint]
address = "127.0.0.1:8500"
scheme = "http"
token = "9999999999999999999999999"
[accessLog]
[log]
level = "DEBUG"
ldez
October 31, 2020, 10:38am
11
Could you give the full logs (from the start of Traefik):
when you are using normalize
when you are using Host(`{{ .Name }}.192.168.1.201.nip.io`)
you can use a pastebin or a gist if the logs are too large.
Nevermind! I found out why.
The problem is I use Nomad templating to write the config toml. so {{ .Name }}
is interpreted by nomad and not written in the config file to be interpreted by Traefik!
I just need to escape this now. Maybe it's also the case for OP
1 Like
@dmikalova this configuration did the trick:
[providers.consulCatalog]
prefix = "traefik"
exposedByDefault = true
defaultRule = "Host(`{{"{{ .Name }}"}}.192.168.1.201.nip.io`)"
system
Closed
November 3, 2020, 11:25am
14
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.