Traefik Ingress Stripprefix

发布于 2025-02-05 19:48:01 字数 687 浏览 3 评论 0原文

使用Traefik作为入口控制器,并寻找一种剥离前缀的方法。由于这些前缀的路径部分将“转发”到服务上,除非服务也在同一路径上聆听,那么该服务将达到404。在文档中,如何删除转发路径,是否很清楚,有没有指针?

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: azure-vote-route
  namespace: azure-vote
spec:
  rules:
    - host: <>.<>.cloudapp.azure.com
      http:
        paths:
        # - path: /
        #   pathType: Prefix
        #   backend:
        #     service:
        #       name: azure-vote-front
        #       port:
        #         number: 80
        - path: /foo
          pathType: Prefix
          backend:
            service:
              name: azure-vote-front
              port:
                number: 80

Using traefik as the ingress controller and looking for a way to stripping path prefixing. as these prefixed path section is "forwarded" to the service unless the service is also listening on a same path, the service will hit a 404. it was not very clear on the docs how to remove the forwarded paths, any pointers?

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: azure-vote-route
  namespace: azure-vote
spec:
  rules:
    - host: <>.<>.cloudapp.azure.com
      http:
        paths:
        # - path: /
        #   pathType: Prefix
        #   backend:
        #     service:
        #       name: azure-vote-front
        #       port:
        #         number: 80
        - path: /foo
          pathType: Prefix
          backend:
            service:
              name: azure-vote-front
              port:
                number: 80

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

少女净妖师 2025-02-12 19:48:01

找到答案

选项1
善良:入口
并使用Traefik的中间件剥离前缀。并且使用入学定义上的注释来驳斥此中间件
&lt; Middlewear的命名空间&gt; - &lt; Middlewear的名称&gt;

eg

apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: ingress-stripprefix
  namespace: azure-vote
spec:
  stripPrefix:
    prefixes:
      - /foo

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-a
  namespace: azure-vote
  annotations:
    traefik.ingress.kubernetes.io/router.middlewares: azure-vote-ingress-stripprefix@kubernetescrd
spec:
  rules:
    - host: <>.<>.cloudapp.azure.com
      http:
        paths:
          - path: /foo
            pathType: Prefix
            backend:
              service:
                name:  azure-vote-front
                port:
                  number: 80

选项2
类型:IngressRoute(这是Traefik特定的入口实现。)

apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: ingressroute-middle
  namespace: azure-vote
spec:
  entryPoints:
    - web
  routes:
    - match: Host(`<>.cloudapp.azure.com`) && PathPrefix(`/test`)
      kind: Rule
      services:
        - name: azure-vote-front
          port: 80
      middlewares:
        - name: testmiddle
    - match: Host(`<>.cloudapp.azure.com`)
      kind: Rule
      services:
        - name: azure-vote-front
          port: 80
      middlewares:
        - name: testmiddle
---
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: testmiddle
  namespace: azure-vote
spec:
  stripPrefix:
    prefixes:
      - /test

found the answers

option 1
kind: Ingress
and using a Middleware from traefik to strip the prefix. and this middleware is refereed using an annotation on the Ingress definition
<namespace-of-middlewear>-<name-of-middlewear>

eg

apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: ingress-stripprefix
  namespace: azure-vote
spec:
  stripPrefix:
    prefixes:
      - /foo

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-a
  namespace: azure-vote
  annotations:
    traefik.ingress.kubernetes.io/router.middlewares: azure-vote-ingress-stripprefix@kubernetescrd
spec:
  rules:
    - host: <>.<>.cloudapp.azure.com
      http:
        paths:
          - path: /foo
            pathType: Prefix
            backend:
              service:
                name:  azure-vote-front
                port:
                  number: 80

option 2
kind: IngressRoute (which is a traefik specific ingress implementation.)

apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: ingressroute-middle
  namespace: azure-vote
spec:
  entryPoints:
    - web
  routes:
    - match: Host(`<>.cloudapp.azure.com`) && PathPrefix(`/test`)
      kind: Rule
      services:
        - name: azure-vote-front
          port: 80
      middlewares:
        - name: testmiddle
    - match: Host(`<>.cloudapp.azure.com`)
      kind: Rule
      services:
        - name: azure-vote-front
          port: 80
      middlewares:
        - name: testmiddle
---
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
  name: testmiddle
  namespace: azure-vote
spec:
  stripPrefix:
    prefixes:
      - /test
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文