Issue defining traefik labelselector in traefik.toml vs. container arg

7/5/2017

I have a traefik.toml file defined as part of my traefik configmap. The snippet below is the kubernetes endpoint configuration with a labelselector defined:

[kubernetes]
  labelselector = "expose=internal"

When I check the traefik status page in this configuration, I see all ingresses listed, not just those with the label "expose: internal" defined.

If I set the kubernetes.labelselector as a container argument to my deployment, however, only the ingresses with the matching label are displayed on the traefik status page as expected:

- --kubernetes.labelselector=expose=internal

According to the Kubernetes Ingress Backend documentation, any label selector format valid in the label selector section of the Labels and Selectors should be valid in the traefik.toml file. I have experimented with both the equality baed (as shown above) and the set-based (to determine if the "expose" label is present, only), neither of which have worked in the toml. The set-based does not seem to work in the container args, but the equality statements do.

I'm assuming there is some issue related to how I've formatted the kubernetes endpoint within the traefik.toml file. Before reporting this issue to github I was hoping someone could clarify the documentation and/or correct any mistakes I've made in the toml file format.

-- Ted W.
kubernetes
traefik

3 Answers

7/5/2017

The problem appears to be the mixing and matching of command line arguments and toml options.

After reading over a few bug reports and some additional misc. documentation I realized that we had enabled the kubernetes backend passing the --kubernetes argument to the traefik container. I realized that defining [kubernetes] in the toml was also enabling the kubernetes backend. On a hunch I removed the command line argument and put the full kubernetes backend config in the toml and everything works as expected.

I'm not sure if this is expected behavior or not but this behavior would seem to suggest it's designed in such a way that command line arguments take precedence over toml config options when duplicate options are provided.

-- Ted W.
Source: StackOverflow

7/5/2017

As you have already found out, not passing --kubernetes makes things work for you. The reason is that this parameter not only enables the Kubernetes provider but also sets all defaults. As documented, the command-line arguments take precedence over the configuration file; thus, any non-default Kubernetes parameters specified in the TOML file will be overridden by the default values implied through --kubernetes. This is intended (albeit not ideally documented) behavior.

You can still mix and match both command-line and TOML configuration parameters for Kubernetes (or any other provider, for that matter) by omitting --kubernetes. For instance, you could have your example TOML file

[kubernetes]
  labelselector = "expose=internal"

and then invoke Traefik like

./traefik --configfile=config.yaml --kubernetes.namespaces=other

which will cause Traefik to use both the custom label selector expose=internal and watch the namespace other.

I have submitted a PR to clarify the behavior of the command-line provider-enabling parameters with regards to the provider default values.

-- Timo Reimann
Source: StackOverflow

7/5/2017

Indeed, flags take precedence over toml config. It's documented here http://docs.traefik.io/basics/#static-trfik-configuration :)

-- Emile VAUGE
Source: StackOverflow