<p>I'm using k3s v1.22.7 on Ubuntu 20.04. I want <code>/bar/xyz</code> to be <code>/xyz</code> to the pods. Without the middleware I'm properly routed to the pods, with it I get <code>404</code> from Traefik as though the stripping from <code>replacePathRegex</code>/<code>stripPrefix</code> happens before the Ingress path evaluation. Examples online all have it like that though...</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: strip-prefix
spec:
  #replacePathRegex:
  #  regex: ^/(?:[^/]+)/(.*)
  #  replacement: /$1
  stripPrefix:
    prefixes:
      - /bar
      - /baz
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: foo-ingress
  annotations:
    kubernetes.io/ingress.class: traefik
    traefik.ingress.kubernetes.io/router.middlewares: strip-prefix@kubernetescrd
spec:
  rules:
  - host: example.org
    http:
      paths:
      - path: /bar
        pathType: Prefix
        backend:
          service:
            name: foo-service
            port:
              number: 5001
      - path: /baz
        pathType: Prefix
        backend:
          service:
            name: foo-service
            port:
              number: 5002
</code></pre>

<p>Looks like the middleware needs the namespace prefixed, so either</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: strip-prefix
  # No namespace defined
spec:
  stripPrefixRegex:
    regex:
    - ^/[^/]+
---
kind: Ingress
metadata:
  annotations:
    traefik.ingress.kubernetes.io/router.middlewares: default-strip-prefix@kubernetescrd
</code></pre>
<p>or</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: strip-prefix
  namespace: example # Namespace defined
spec:
  stripPrefixRegex:
    regex:
    - ^/[^/]+
---
kind: Ingress
metadata:
  annotations:
    traefik.ingress.kubernetes.io/router.middlewares: example-strip-prefix@kubernetescrd
</code></pre>
<p>should work.</p>
<p>(<a href="https://community.traefik.io/t/how-to-configure-middleware-with-kubernetes-ingress-middleware-xyz-does-not-exist/5016" rel="noreferrer">Source</a>)</p>
