Traefik 在路由具有部分重叠名称和重写规则的路由时遇到问题

Traefik having troubles with routing routes with partially overlapping names and rewrite rules

我在设置带有重写的入口路由时遇到了问题。 我的入口定义:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: mw-abcd
spec:
  rules:
  - http:
      paths:
      - path: /abcd/v1
        backend:
          serviceName: mw-abcd-v1
          servicePort: 80
      - path: /abcd/v2
        backend:
          serviceName: mw-abcd-v2
          servicePort: 80
---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: mw-abcd-backward-comp
  annotations:
    traefik.ingress.kubernetes.io/rewrite-target: /abcd/v1
spec:
  rules:
  - http:
      paths:
      - path: /abcd
        backend:
          serviceName: mw-abcd-v1
          servicePort: 80

我想在这里实现的是,每个没有 /v1 后缀的请求都应该重定向到带有这个后缀的后端,并且包含版本的请求应该按原样路由。发生的事情是带有 /v1 的那些无论如何都被重定向到 /v1/v1。所以当务之急是先抓住第​​二条规则。我尝试通过适当的注释手动设置优先级:

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: mw-abcd
  annotations:
    traefik.ingress.kubernetes.io/priority: "1"
spec:
  rules:
  - http:
      paths:
      - path: /abcd/v1
        backend:
          serviceName: mw-abcd-v1
          servicePort: 80
      - path: /abcd/v2
        backend:
          serviceName: mw-abcd-v2
          servicePort: 80

---
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
  name: mw-abcd-backward-comp
  annotations:
    traefik.ingress.kubernetes.io/rewrite-target: /abcd/v1
    traefik.ingress.kubernetes.io/priority: "2"
spec:
  rules:
  - http:
      paths:
      - path: /abcd
        backend:
          serviceName: mw-abcd-v1
          servicePort: 80

但随后一切都将进入默认后端并重新运行 404。

知道这里出了什么问题吗?

我在这里找到了答案。根据有关优先级的文档 (https://docs.traefik.io/basics/#priorities):

By default, routes will be sorted (in descending order) using rules length (to avoid path overlap): PathPrefix:/foo;Host:foo.com (length == 28) will be matched before PathPrefixStrip:/foobar (length == 23) will be matched before PathPrefix:/foo,/bar (length == 20).

我以错误的方式设置了优先级,指定的数字必须足够大(大于其他路由的长度)才能覆盖默认行为。所以我最终得到了 priority 值,例如 90100