4

I have the following kubernetes manifest

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  annotations:
    kubernetes.io/ingress.class: traefik-external
    traefik.ingress.kubernetes.io/router.entrypoints: websecure, web
    traefik.ingress.kubernetes.io/rule-type: PathPrefixStrip
  name: ingressname
  namespace: thenamespace
spec:
  rules:
  - host: my.host
    http:
      paths:
      - backend:
          serviceName: theservice
          servicePort: 8080
        path: /api

Havin an service, theservice, that listens to / I would expect the url my.host/api/something/anotherthing match to /something/anotherthing in theservice. That doesn't happen for me though, I get a 404 back.

Any ideas what might be wrong?

4
  • How did you install traefik? Any specific option used? Which K8s version are you using?
    – acid_fuji
    Commented Oct 28, 2020 at 11:09
  • Also which traefik version are u using?
    – acid_fuji
    Commented Oct 29, 2020 at 9:17
  • 1
    It was version 2, so I needed to add some middelware to get it working. Commented Nov 3, 2020 at 21:44
  • That's what I suspected since v2 they introduce a lot of changes. I`ll place a short answer for better visibility.
    – acid_fuji
    Commented Nov 4, 2020 at 8:16

1 Answer 1

6

During the transition from v1 to v2, a number of internal pieces and components of Traefik were rewritten and reorganized. As such, the combination of core notions such as frontends and backends has been replaced with the combination of routers, services, and middlewares.

With v2 transforming the URL path prefix of incoming requests is configured with middlewares object, after the routing step with router rule PathPrefix.

With v1 it is defined at ingress level:

    apiVersion: networking.k8s.io/v1beta1
    kind: Ingress
    metadata:
      name: traefik
      annotations:
        kubernetes.io/ingress.class: traefik
        traefik.ingress.kubernetes.io/rule-type: PathPrefixStrip
    spec:
      rules:
      - host: company.org
        http:
          paths:
          - path: /admin
            backend:
              serviceName: admin-svc
              servicePort: admin

With v2 you have define also middleware object alongside ingress-route:


apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: http-redirect-ingressroute
  namespace: admin-web
spec:
  entryPoints:
    - web
  routes:
    - match: Host(`company.org`) && PathPrefix(`/admin`)
      kind: Rule
      services:
        - name: admin-svc
          port: admin
      middlewares:
        - name: admin-stripprefix
---
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: admin-stripprefix
spec:
  stripPrefix:
    prefixes:
      - /admin

More information can be found here: Frontends and Backends Are Dead...
... Long Live Routers, Middlewares, and Services

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.