【问题标题】:Can you forward traffic to a dynamic service using Traefik?您可以使用 Traefik 将流量转发到动态服务吗?
【发布时间】:2021-10-05 13:47:41
【问题描述】:

下面是一个例子IngressRoute

我想要这样的东西,其中域的第一部分将映射到 Kubernetes 服务,而不必静态定义服务名称。

service1.api.test.com -> service1

service2.api.test.com -> service1

apiVersion: traefik.containo.us/v1alpha1
kind: IngressRoute
metadata:
  name: ingressroute
  namespace: default
spec:
  entryPoints:
    - web
  routes:
  - match: "HostRegexp(`{subdomain:[a-z]+}.api.test.com`)"
    kind: Rule
    services:
    - name: whoami  # can this be dynamic?
      port: 80

【问题讨论】:

    标签: kubernetes traefik


    【解决方案1】:

    不,这是不可能的。因为即使您能够匹配主机正则表达式,它也不知道请求需要转到哪个服务。

    因此,您需要为同一 ingressRoute 中的不同服务创建两个单独的匹配项

    apiVersion: traefik.containo.us/v1alpha1
    kind: IngressRoute
    metadata:
      name: ingressroute
      namespace: default
    spec:
      entryPoints:
        - web
      routes:
      - match: "HostRegexp(`someservice.yourdomain.com`) && PathPrefix(`/`)"
        kind: Rule
        services:
        - name: whoamiV1
          port: 80
      - match: "HostRegexp(`yourdomain.com`,`{subdomain:[a-zA-Z0-9-]+}.yourdomain.com`) &&PathPrefix(`/api/someservice/`)"
        kind: Rule
        services:
        - name: whoamiV2
          port: 80
    

    更多详情可以参考docs

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-10
      • 1970-01-01
      • 1970-01-01
      • 2010-12-16
      • 1970-01-01
      • 1970-01-01
      • 2020-01-09
      • 1970-01-01
      相关资源
      最近更新 更多