gpt4 book ai didi

kubernetes - 如何去除 Kubernetes Traefik ingress 中的路径前缀?

转载 作者:行者123 更新时间:2023-12-02 18:17:27 27 4
gpt4 key购买 nike

我在 Ubuntu 20.04 上使用 k3s v1.22.7。我希望 /bar/xyz 成为 Pod 的 /xyz。如果没有中间件,我会正确地路由到 pod,有了它,我从 Traefik 得到 404,就好像从 replacePathRegex/stripPrefix 中剥离发生在之前入口路径评估。网上的例子都是这样的...

apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: strip-prefix
spec:
#replacePathRegex:
# regex: ^/(?:[^/]+)/(.*)
# replacement: /$1
stripPrefix:
prefixes:
- /bar
- /baz
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: foo-ingress
annotations:
kubernetes.io/ingress.class: traefik
traefik.ingress.kubernetes.io/router.middlewares: strip-prefix@kubernetescrd
spec:
rules:
- host: example.org
http:
paths:
- path: /bar
pathType: Prefix
backend:
service:
name: foo-service
port:
number: 5001
- path: /baz
pathType: Prefix
backend:
service:
name: foo-service
port:
number: 5002

最佳答案

看起来中间件需要命名空间前缀,所以要么

apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: strip-prefix
# No namespace defined
spec:
stripPrefixRegex:
regex:
- ^/[^/]+
---
kind: Ingress
metadata:
annotations:
traefik.ingress.kubernetes.io/router.middlewares: default-strip-prefix@kubernetescrd

apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: strip-prefix
namespace: example # Namespace defined
spec:
stripPrefixRegex:
regex:
- ^/[^/]+
---
kind: Ingress
metadata:
annotations:
traefik.ingress.kubernetes.io/router.middlewares: example-strip-prefix@kubernetescrd

应该可以。

( Source )

关于kubernetes - 如何去除 Kubernetes Traefik ingress 中的路径前缀?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71398933/

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