I'm using Traefik 2.2.0-rc3 on a new k8s cluster, basically set up as documented on docs.traefik.io. All in all it works, but I can't figure out how to get middlewares working.
I have also tried the kubernetes-crd setup, where adding middlewares wasn't a problem, but I prefer the kubernetes-ingress way for its smaller deployment manifests.
Adding the router.middlewares annotation in the config shown below only let to an error message:
middleware "traefik-basic-auth@kubernetescrd" does not exist
I guess @kubernetescrd might be wrong. According to these docs it should be the provider namespace, but I'm not sure what is the correct value in my case.
I've stumbled across that one myself. But fortunately a look at the dashboard helped me. If you define the middleware via the annotations, you have to put the Kubernetes namespace in front of it. That looks like this
My middleware is called "secureheaders" and the namespace is "ingress-traefik"
This should definitely be better documented, because it is very confusing. But at least there is the possibility to access middlewares across the namespace.
Yes, that's right. In your case, the middleware would be called: default-path-prefix@kubernetescrd
But to be honest. So far I could only access the middlewares via annotations in an ingress object. I also tried using the CLI arguments, because I wanted to configure a default middleware for my entry point.
Thanks @p7k .
It is not clear to me whether your solution is working for you or not.
Watching my configuration in my first answer, apart from the prefix / provider syntax in "dynamic middleware" configuration in the Ingress definition, how far I am from your solution?
How do you configure traefik in the container in the pod?
I'm not quite sure what you mean. You are trying to define a middleware in a normal k8s ingress object (talk about the kubernetesingress provider). In this case only the kubernetes namespace prefix is missing.
If you want to define the middleware as default in an entrypoint (using the CLI arguments), I don't think this works yet. I haven't got it working yet either.
Example for an ingress object with kubernetesingress provider:
Thanks a lot @p7k
You save my live. 3 days frustrated on how make traefik ingress v2 to works as expected, from listening on host port 443 until stuck in this middleware things
What left now is how to define middleware in something centralized such as the cli parameter, and refer it from anywhere
Unfortunately this cannot be defined in the CLI. This is because there are "dynamic" and "static" configurations. Only static configurations can be adjusted using the CLI. But it is definitely possible to create "ready-made" middlewares in the Traefik namespace, which in turn can be accessed from anywhere (with the appropriate namespace prefix). This is what I do, for example, with a middleware for the HSTS header, which I don't have to redefine in every namespace.
I think we've had the same problem here before. Unfortunately I can't find the link to it. But the solution was probably to set the tls option not in the router (Ingress annotations), but globally in the corresponding entry point definition (EntryPoints | Traefik | v2.2). The tls option should only be set in one entry point, so that this is probably not possible via the annotations, at least not currently. But the global configuration works great here, for example, with a similar setup and a https redirect.
can you please tell me the how to replace this traefik.ingress.kubernetes.io/router.tls: "true"
I had to use this in all of my ingress files . how to use --entrypoints.websecure.http.tls.options can you brief me with example .what changes i had to do