Traefik without custom ressource definitions

Hello,
we are currently switching from Traefik v1 to v2 in our k8s.
We widely use the feature of path prefix stripping with the ingress annotation "traefik.frontend.rule.type: PathPrefixStrip" which is removed in v2.
As far as is understand Middlewares are in the v2 necessary to do path prefix stripping. Our problem is that we do not have cluster admin rights and therefore cannot deploy custom ressource definitions.

We tried something like this in the traefik.toml, but it does not work as expected. Do we miss something here?

    [http.middlewares]
      [http.middlewares.service1.stripPrefix]
        prefix = "/service1"
        forceSlash = false
      [http.middlewares.service2.stripPrefix]
        prefix = "/service2"
        forceSlash = false
    [http.routers]
      [http.routers.service1]
        rule = "Path(`/service1`)"
        middlewares = ["service1"]
        service = "service1"
      [http.routers.service2]
        rule = "Path(`/service2`)"
        middlewares = ["service2"]
        service = "service2"

Is there any other option to use traefik with path prefix stripping?

thanks in advance

Hi @swfox,
Thanks for your interest in Traefik.

It seems you have a typo on your prefix. The middleware is waiting for a list of prefix:

[http.middlewares]
  [http.middlewares.example.stripPrefix]
    prefixes = ["/foobar"]
    forceSlash = false

Hi @moutoum ,
thanks for the hint. I changed my config acordingly, but it still does not work.

I took a look into the dashboard and the routes and middlewares seem not to be instantiated.
The section HTTP Middlewares show only two entries related to the dashboard.

In the section routing there are only the generated routes from my ingresses which shows an error like:
middleware "file-service1@kubernatescrd" does not exist
I have referenced the configuration in the ingress with this annotation:
traefik.ingress.kubernetes.io/router.middlewares: file-service1@kubernatescrd
like described in your documentation.

Is there also a typo in the naming? I'm not shure if I correctly understand the concatenation of the name.

Can you please use the following naming convention:

<middleware-namespace>-<middleware-name>@kubernetescrd

Please learn more about provider namespace and its Kubernetes specific configuration

what is the <middleware-namespace> if the middleware is defined in the config toml like above?

edit: fix formating

If the middleware is specified in a config file the name should be the following:

name@file

where name is the middleware name defined in the configuration file and file is the provider name, and in that case, it is the file.

Hope that helps,

thank you for the info! I couldnt find this in the documentation.

But if i look into the dashboard it still says ERRORS middleware "service1@file" does not exist. Do I have to configure something else to get the middleware from the config toml working?

If you can not apply that middleware it has not been created by Traefik. I would suggest having a look at the log files, especially while Traefik is starting, see the first lines that should be a lot of crucial information about what has been loaded and if there are errors you should see them.

Fingers crossed!

These are the first lines of the traefik starting.
It says that the middleware is not existing, but I cannot see what the problem is?

time="2022-05-19T13:53:06Z" level=info msg="Configuration loaded from file: /config/traefik.toml"
time="2022-05-19T13:53:06Z" level=info msg="Traefik version 2.2.8 built on 2020-07-28T15:46:03Z"
time="2022-05-19T13:53:06Z" level=info msg="\nStats collection is disabled.\nHelp us improve Traefik by turning this feature on :)\nMore details on: https://docs.traefik.io/contributing/data-collection/\n"
time="2022-05-19T13:53:06Z" level=info msg="Starting provider aggregator.ProviderAggregator {}"
time="2022-05-19T13:53:06Z" level=info msg="Starting provider *ingress.Provider {\"namespaces\":[\"<namespace>\"],\"ingressClass\":\"<my-ingress-class>\"}"
time="2022-05-19T13:53:06Z" level=info msg="ingress label selector is: \"\"" providerName=kubernetes
time="2022-05-19T13:53:06Z" level=info msg="Creating in-cluster Provider client" providerName=kubernetes
time="2022-05-19T13:53:06Z" level=info msg="Starting provider *traefik.Provider {}"
time="2022-05-19T13:53:07Z" level=error msg="middleware \"service1@file\" does not exist" routerName=service1-<namespace>-<url>-service1@kubernetes 
entryPointName=http
time="2022-05-19T13:53:07Z" level=error msg="middleware \"service1@file\" does not exist" entryPointName=metrics routerName=service1-<namespace>-<url>-service1@kubernetes
10.75.148.73 - - [19/May/2022:13:53:07 +0000] "GET /ping HTTP/1.1" 200 2 "-" "-" 1 "ping@internal" "-" 8ms
10.75.148.73 - - [19/May/2022:13:53:14 +0000] "GET /ping HTTP/1.1" 200 2 "-" "-" 2 "ping@internal" "-" 0ms
10.75.148.73 - - [19/May/2022:13:53:24 +0000] "GET /ping HTTP/1.1" 200 2 "-" "-" 3 "ping@internal" "-" 0ms