gpt4 book ai didi

Kubernetes入口中基于Traefik路径的路由无法按预期工作

转载 作者:行者123 更新时间:2023-12-04 15:50:12 25 4
gpt4 key购买 nike

我正在尝试使用Kubernetes中Traefik入口 Controller 提供的基于路径的路由机制,但URL重写存在一些问题。

我的[更新]配置如下

apiVersion: extensions/v1beta1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: traefik
traefik.ingress.kubernetes.io/auth-type: "basic"
traefik.ingress.kubernetes.io/auth-tls-insecure: "true"
traefik.ingress.kubernetes.io/frontend-entry-points: "http,https"
traefik.ingress.kubernetes.io/app-root: "/"
traefik.ingress.kubernetes.io/rule-type: "PathPrefixStrip"
traefik.ingress.kubernetes.io/rewrite-target: "/"
name: webapp-ingress
namespace: my-company
spec:
rules:
- host: local-ubuntu
- http:
paths:
- path: /
backend:
serviceName: webapp
servicePort: 80
- path: /db
backend:
serviceName: db-manager
servicePort: 8081

流量被路由到正确的服务,但是当我查看db-manager(kubernetes)服务的日志时,URL仍带有/db前缀。
我对PathPrefixStrip的期望是,将在没有/db前缀的情况下将流量路由到运行db-manager微服务的容器,该容器正在后端监听/( http://db-manager:8081)。

我想念什么吗? traefik或仅nginx支持它吗?
预先感谢您的反馈。

[编辑]

更具体地说,我将在下面讨论的当前注释中观察以下内容
  • traefik.ingress.kubernetes.io/规则类型:“PathPrefixStrip”
  • traefik.ingress.kubernetes.io/rewrite-target:“/”

  • 网址: http://local-ubuntu/db [确定]-> 200

    然后正在加载其他资源,但指向错误的基本URL

    例子:

    资源网址为: http://local-ubuntu/public/css/bootstrap.min.css

    但这应该是: http://local-ubuntu/db/public/css/bootstrap.min.css
    (当我手动尝试时可以使用)

    我不确定当前配置中缺少的内容。

    最佳答案

    关于不提供静态内容,文档指出以下内容:

    Use a *Strip matcher if your backend listens on the root path (/) but should be routeable on a specific prefix. For instance, PathPrefixStrip: /products would match /products but also /products/shoes and /products/shirts. Since the path is stripped prior to forwarding, your backend is expected to listen on /. If your backend is serving assets (e.g., images or Javascript files), chances are it must return properly constructed relative URLs. Continuing on the example, the backend should return /products/shoes/image.png (and not /images.png which Traefik would likely not be able to associate with the same backend). The X-Forwarded-Prefix header (available since Traefik 1.3) can be queried to build such URLs dynamically.

    关于Kubernetes入口中基于Traefik路径的路由无法按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54412786/

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