[英]How do I get traefik.ingress.kubernetes.io/rule-type: PathPrefixStrip to work?
I have the following kubernetes manifest我有以下 kubernetes 清单
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: traefik-external
traefik.ingress.kubernetes.io/router.entrypoints: websecure, web
traefik.ingress.kubernetes.io/rule-type: PathPrefixStrip
name: ingressname
namespace: thenamespace
spec:
rules:
- host: my.host
http:
paths:
- backend:
serviceName: theservice
servicePort: 8080
path: /api
Havin an service, theservice
, that listens to /
I would expect the url my.host/api/something/anotherthing
match to /something/anotherthing
in theservice
.就吃的服务, theservice
,侦听/
我期望的URL my.host/api/something/anotherthing
匹配/something/anotherthing
在theservice
。 That doesn't happen for me though, I get a 404 back.不过,这不会发生在我身上,我得到了一个 404。
Any ideas what might be wrong?任何想法可能有什么问题?
During the transition from v1 to v2, a number of internal pieces and components of Traefik were rewritten and reorganized.在从 v1 到 v2 的过渡期间,Traefik 的许多内部部分和组件被重写和重组。 As such, the combination of core notions such as frontends and backends has been replaced with the combination of routers , services , and middlewares .因此,前端和后端等核心概念的组合已被路由器、服务和中间件的组合所取代。
With v2 transforming the URL path prefix of incoming requests is configured with middlewares object, after the routing step with router rule PathPrefix
.在 v2 转换中,传入请求的 URL 路径前缀配置有中间件对象,在路由步骤之后使用路由器规则PathPrefix
。
With v1 it is defined at ingress level:使用 v1,它是在入口级别定义的:
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: traefik
annotations:
kubernetes.io/ingress.class: traefik
traefik.ingress.kubernetes.io/rule-type: PathPrefixStrip
spec:
rules:
- host: company.org
http:
paths:
- path: /admin
backend:
serviceName: admin-svc
servicePort: admin
With v2 you have define also middleware object alongside ingress-route:在 v2 中,您还定义了 ingress-route 旁边的中间件对象:
apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
name: http-redirect-ingressRoute
namespace: admin-web
spec:
entryPoints:
- web
routes:
- match: Host(`company.org`) && PathPrefix(`/admin`)
kind: Rule
services:
- name: admin-svc
port: admin
middlewares:
- name: admin-stripprefix
---
kind: Middleware
metadata:
name: admin-stripprefix
spec:
stripPrefix:
prefixes:
- /admin
More information can be found here: Frontends and Backends Are Dead...可以在此处找到更多信息: 前端和后端已死...
... Long Live Routers, Middlewares, and Services ... 万岁路由器、中间件和服务
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.