简体   繁体   中英

How do I get traefik.ingress.kubernetes.io/rule-type: PathPrefixStrip to work?

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM