首页 > 解决方案 > Istio 虚拟服务匹配 uri 和 cookie 不起作用

问题描述

我一直在尝试将此虚拟服务 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,如下图所示: 在此处输入图像描述

邮递员设置如下: 在此处输入图像描述

标签: networkingkubernetesmicroservicesistio

解决方案


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

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

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

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


推荐阅读