【问题标题】:Istio Virtual Service match uri and cookie not workingIstio 虚拟服务匹配 uri 和 cookie 不起作用
【发布时间】:2019-09-14 13:41:37
【问题描述】:

我一直在尝试将此虚拟服务 yaml 应用于我的微服务:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: nameko-notifyms
spec:
  hosts:
  - "*"
  gateways:
  - nameko-notifyms-gateway
  http:
  - match:
    - headers:
        cookie:
          regex: "^(.*?;)?(user=joe)(;.*)?"
      uri:
        exact: /hello
    route:
    - destination:
        host: nameko-notifyms
        port:
          number: 8000

使用上面的代码块,在 curl uri 之后,没有流量进入 pod。

如果我注释掉如下代码块所示的信息:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: nameko-notifyms
spec:
  hosts:
  - "*"
  gateways:
  - nameko-notifyms-gateway
  http:
  - match:
#    - headers:
#        cookie:
#          regex: "^(.*?;)?(user=joe)(;.*)?"
    - uri:
        exact: /hello
    route:
    - destination:
        host: nameko-notifyms
        port:
          number: 8000

流量被定向到 pod,如下图所示:

邮递员设置如下:

【问题讨论】:

  • 你用什么卷曲做测试?
  • @VasilyAngapov 我实际上正在使用 Postman,将在我的 cookie 中添加屏幕截图。
  • 可能regex 字符串有误,试试看:^(.*?;)?(user=joe)(;.*)?$

标签: networking kubernetes microservices istio


【解决方案1】:

您好,问题很老,但仍然存在,所以这里是解决方案: 问题来自正则表达式,第一个块 ; 不是可选的。

这里是更正的正则表达式。

"^(.*;?)?(user=joe)(;.*)?"

这里有完整的细节:https://regex101.com/r/CPv2kU/3

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-10-18
    • 2021-09-21
    • 2019-12-21
    • 2019-07-19
    • 2020-09-07
    • 1970-01-01
    • 2021-08-20
    • 1970-01-01
    相关资源
    最近更新 更多