gpt4 book ai didi

kubernetes-ingress - Traefik Ingress 重写目标什么都不做

转载 作者:行者123 更新时间:2023-12-05 01:25:33 26 4
gpt4 key购买 nike

我有一个响应 / 的后端服务,但我希望它在入口路由 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: /$1
...
- path: /overview(.*)

但是这些导致入口 /overview 请求未到达后端时出现 404。

总而言之,我希望 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

关于kubernetes-ingress - Traefik Ingress 重写目标什么都不做,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70789020/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com