Traefik Ingress 重写目标什么都不做
Traefik Ingress rewrite-target does nothing
我有一个响应 /
的后端服务,但我希望它在入口路由 myhost.com/overview
上响应 运行。无论我尝试哪种配置,traefik 都不会删除路径 /overview
- 我可以看到后端得到 /overview
.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: registry-ingress
namespace: ingress
annotations:
kubernetes.io/ingress.class: traefik
traefik.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: myhost.com
http:
paths:
- path: /overview
pathType: Prefix
backend:
service:
name: overview
port:
number: 8079
我试过几个变体:
traefik.ingress.kubernetes.io/rewrite-target: /
...
- path: /overview(.*)
但是这些导致入口处出现 404 /overview
请求未到达后端。
总而言之,我希望 https://myhost.com/overview/
在 /
到达后端。
Traefik 不支持 traefik.ingress.kubernetes.io/rewrite-target
注解。请在此处查看可用注释列表:https://doc.traefik.io/traefik/routing/providers/kubernetes-ingress/#annotations
但是您的目标可以使用 StipPrefix 中间件来实现。
---
# Middleware
# Strip prefix /overview
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: mw-admin
namespace: ingress
spec:
stripPrefix:
forceSlash: false
prefixes:
- /overview
---
# Ingress
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: registry-ingress
namespace: ingress
annotations:
kubernetes.io/ingress.class: traefik
traefik.ingress.kubernetes.io/router.middlewares: ingress-mw-admin@kubernetescrd
spec:
tls:
- hosts:
- myhost.com
secretName: tls-secret
rules:
- host: myhost.com
http:
paths:
- path: /overview
pathType: Prefix
backend:
service:
name: overview
port:
number: 8079
我有一个响应 /
的后端服务,但我希望它在入口路由 myhost.com/overview
上响应 运行。无论我尝试哪种配置,traefik 都不会删除路径 /overview
- 我可以看到后端得到 /overview
.
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: registry-ingress
namespace: ingress
annotations:
kubernetes.io/ingress.class: traefik
traefik.ingress.kubernetes.io/rewrite-target: /
spec:
rules:
- host: myhost.com
http:
paths:
- path: /overview
pathType: Prefix
backend:
service:
name: overview
port:
number: 8079
我试过几个变体:
traefik.ingress.kubernetes.io/rewrite-target: /
...
- path: /overview(.*)
但是这些导致入口处出现 404 /overview
请求未到达后端。
总而言之,我希望 https://myhost.com/overview/
在 /
到达后端。
Traefik 不支持 traefik.ingress.kubernetes.io/rewrite-target
注解。请在此处查看可用注释列表:https://doc.traefik.io/traefik/routing/providers/kubernetes-ingress/#annotations
但是您的目标可以使用 StipPrefix 中间件来实现。
---
# Middleware
# Strip prefix /overview
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: mw-admin
namespace: ingress
spec:
stripPrefix:
forceSlash: false
prefixes:
- /overview
---
# Ingress
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: registry-ingress
namespace: ingress
annotations:
kubernetes.io/ingress.class: traefik
traefik.ingress.kubernetes.io/router.middlewares: ingress-mw-admin@kubernetescrd
spec:
tls:
- hosts:
- myhost.com
secretName: tls-secret
rules:
- host: myhost.com
http:
paths:
- path: /overview
pathType: Prefix
backend:
service:
name: overview
port:
number: 8079