I'm having troubles with setting up ingress routes with rewrite. My ingress definitions:
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
What I want to achieve here is that every request without /v1
suffix should be redirected to the backend with this suffix and the ones including version should be routed as is. What happens is that the ones with /v1
are redirected to /v1/v1
anyway. So the priority is to grab the second rule as first. I've tried to setup priorities manually by proper annotations:
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
but then everything is going to default backend and retruning 404.
Any ideas what's wrong here?
I managed to find the answer here. According to the documentation about priorities (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).
I was setting the priorities in wwrong way, the specified number must be big enough (bigger than length of other routes) to overwrite the default behavior. So I ended up with priority
values like 90
and 100
.