【问题标题】:VirtualService routing only uses one hostVirtualService 路由只使用一台主机
【发布时间】:2020-01-26 23:11:44
【问题描述】:

我有以下虚拟服务:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: external-vs
  namespace: dev
spec:
  hosts:
    - "*"
  gateways:
    - http-gateway
  http:
    - name: "postauth"
      match:
      - uri:
        exact: /postauth
      route:
        - destination:
            port:
              number: 8080
            host: postauth
    - name: "frontend"
      match:
        - uri:
          exact: /app
      route:
        - destination:
            port:
              number: 8081
            host: sa-frontend

我希望对 /postauth 端点的调用会被路由到 postauth 服务,对 /app 端点的调用会被路由到 sa-frontend 服务。发生的事情是所有调用最终都被路由到文件中的第一个路由器,在上述情况下是 postauth,但如果我更改顺序,它将是 sa-frontend

所有服务和部署都在同一个命名空间 (dev) 中。

这是某种预期的行为吗?我的解释是,上面应该只允许调用 /postauth 和 /app 端点而不是其他任何东西,并将它们路由到它们各自的服务。

【问题讨论】:

  • 这不是预期的行为,因为它应该分别适用于第一个和第二个服务。您是否收到与此问题相关的任何错误?
  • 创建虚拟服务后,istio 路由的输出是什么? istioctl pc routes $(kubectl get pods -l istio=ingressgateway -o jsonpath='{.items[0].metadata.name}' -n istio-system).istio-system -o json 请同时删除此 yaml 中的名称,然后重试。在上面提供的输出中,您应该注意到两个条目的路由。
  • 另外你的 istio 版本是什么?

标签: networking kubernetes istio


【解决方案1】:

根据 HTTPMatchRequest 中的documentaion for Istio 1.3 你可以找到

字段:名称,类型:字符串

我比较了 1.1 和 1.3 版本之间的这些设置: 在 1.3.4 版本中,此参数正常工作,并且使用以下名称传播路由:

[
    {
        "name": "http.80",
        "virtualHosts": [
            {
                "name": "*:80",
                "domains": [
                    "*",
                    "*:80"
                ],
                "routes": [
                    {
                        "name": "ala1",
                        "match": {
                            "prefix": "/hello1",
                            "caseSensitive": true
                        },
                        "route": {
                            "cluster": "outbound|9020||hello1.default.svc.cluster.local",
.
.
.

                    {
                        "name": "ala2",
                        "match": {
                            "prefix": "/hello2",
                            "caseSensitive": true
                        },
                        "route": {
                            "cluster": "outbound|9030||hello2.default.svc.cluster.local",

在 1.1 版中,它无法正常工作。在这些情况下,请使用适当的release 验证您的设置。

另外请参考Troubleshooting部分。

您可以在集群内验证您应用的配置(更改),例如: Envoy 实例是如何配置的:

istioctl proxy-config cluster -n istio-system your_istio-ingressgateway-name

验证服务的路由配置和虚拟主机:

istioctl proxy-config routes -n istio-system your_istio-ingressgateway-name -o json

希望对您有所帮助。

【讨论】:

    猜你喜欢
    • 2021-05-27
    • 2021-10-28
    • 1970-01-01
    • 2018-05-27
    • 2016-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-24
    相关资源
    最近更新 更多