Search code examples
kubernetestraefik

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


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.


Solution

  • 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.