【问题标题】:Istio - redirect request to external urlIstio - 将请求重定向到外部 url
【发布时间】:2021-09-09 23:31:20
【问题描述】:

我正在尝试使用 istio 在 Kubernetes 集群中设置代理服务。我创建了两个不同的域。如果域是 foo.com,则应将其重定向到外部 URL,否则应将其路由到应用服务器。我已经使用虚拟服务和服务条目对此进行了配置。但是当我点击 foo.com 时,它会跳过 Authorization 标头。我需要一个 Authorization 标头来处理请求。有没有办法解决这个问题?提前致谢。

VirtualService.yaml

apiVersion: networking.istio.io/v1beta1
kind: ServiceEntry
metadata:
  name: external-svc-https
spec:
  hosts:
  - foo.com
  location: MESH_EXTERNAL
  ports:
  - number: 443
    name: https
    protocol: TLS
  resolution: DNS
---
kind: VirtualService
apiVersion: networking.istio.io/v1alpha3
metadata:
  name: redirect
  namespace: default
  labels:
    app: foo
    env: staging
spec:
  hosts:
    - foo.com
  gateways:
    - istio-system/gateway
  http:
    - match:
        - uri:
            prefix: /
      redirect:
        authority: bar.com

【问题讨论】:

  • 尝试将您的身份验证标头添加到 VirtualService 标头中的 HTTPRoute:your-auth-header-name: regex: ".*"

标签: kubernetes istio istio-gateway


【解决方案1】:

如果foo.com 域被命中时重定向

apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
  name: github
spec:
  hosts:
  - "raw.githubusercontent.com"
  location: MESH_EXTERNAL
  ports:
  - number: 443
    name: https
    protocol: TLS
  resolution: DNS

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: webserver
spec:
  hosts:
  - foo.com
  http:
  - match:
    - uri:
        regex: ".*"
    rewrite:
      uri: "/mcasperson/NodejsProxy/master/externalservice1.txt"
      authority: raw.githubusercontent.com
    route:
    - destination:
        host: raw.githubusercontent.com
        port:
          number: 443

规则

apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: github
spec:
  host: "raw.githubusercontent.com"
  trafficPolicy:
    tls:
      mode: SIMPLE

阅读更多:https://octopus.com/blog/istio/istio-serviceentry

【讨论】:

  • 非常有帮助,谢谢。
猜你喜欢
  • 1970-01-01
  • 2010-10-18
  • 2023-01-05
  • 2016-12-16
  • 2021-09-10
  • 1970-01-01
  • 2017-12-11
  • 2012-01-10
  • 2012-08-02
相关资源
最近更新 更多