【问题标题】:Istio virtual service spec host and destination rule hostIstio 虚拟服务规范主机和目标规则主机
【发布时间】:2023-01-11 23:58:36
【问题描述】:

我试图理解 Istio 配置模型,但我读得越多就越感到困惑,尤其是在 hostshost 字段周围。在他们的示例中,他们都使用相同的短名称,我不确定他们是指虚拟服务名称、Kubernetes 服务主机名还是dns 服务地址。

假设我有以下配置:

  • 我的 Kubernetees 项目命名空间称为 poc-my-ns
  • poc-my-ns 内,我有我的 pod(版本 1 和 2)Kubernetes 路由和 Kubernetes 服务。
  • 服务主机名是:poc-my-ns.svc.cluster.local,路由是https://poc-my-ns.orgdevcloudapps911.myorg.org
  • 一切都已启动并正在运行,服务选择器从所有版本中获取所有 pod。 (Istio 虚拟服务假设按版本进行最终选择)。

预期的 Istio 配置如下所示:

apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
  name: poc-my-dr
spec:
  host: poc-my-ns.svc.cluster.local # ???
  subsets:
    - name: v1
      labels:
        version: 1.0
    - name: v2
      labels:
        version: 2.0
---
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: poc-my-vs
spec:
  hosts:
    - poc-my-ns.svc.cluster.local # ???
  http:
    - route:
        - destination:
            host: poc-my-dr # ???
            subset: v1
          weight: 70
        - destination:
            host: poc-my-dr # ???
            subset: v2
          weight: 30

我的问题是:

  1. 目标规则spec/host是否引用Kubernetes服务主机名?
  2. 虚拟服务spec/hosts是指Kubernetes服务主机名,是路由https://poc-my-ns.orgdevcloudapps911.myorg.org还是别的?
  3. 虚拟服务spec/http/route/destination/host 是指目标规则名称还是它应该指向Kubernetes 服务主机名或者它应该是虚拟服务metadata/name

    我真的很感激澄清。

【问题讨论】:

    标签: istio


    【解决方案1】:

    VirtualServiceDestinationRule 基本上配置了 istio 网格的 envoy-proxy。 VirtualService 定义了将流量路由到的位置,DestinationRule 定义了对流量的额外处理。

    对于 VS,spec.hosts 列表可以包含 kubernetes 内部和外部主机。

    假设您想要定义如何将来自 kubernetes 集群外部的 api.example.com 的流量通过 istio-ingressgateway my-gateway 路由到网格中。它应该被路由到 store 命名空间中的 rating 应用程序,因此 VS 将如下所示:

    spec:
      hosts:
      - api.example.com # external host
      gateway:
      - my-gateway # the ingress-gateway
      http:
      - [...]
        route:
        - destination:
          host: rating.store.svc.cluster.local # kubernetes service
    

    如果你想定义集群/网格内部流量的路由方式,你可以在spec.hosts列表中设置rating.store.svc.cluster.local并定义mesh网关(或者像你一样将其省略,因为mesh是默认值)和将它路由到 rating.store.svc.cluster.local 服务。您还可以添加一个 DR,在其中定义子集并将所有网格内部流量路由到子集 v1

    # VS
    [...]
    spec:
      hosts:
      - rating.store.svc.cluster.local # cluster internal host
      gateway:
      - mesh # mesh internal gateway (default when omitted)
      http:
      - [...]
        route:
        - destination:
            host: rating.store.svc.cluster.local # cluster internal host
            subset: v1 # defined in destinationrule below
    ---
    [...]
    spec:
      host: rating.store.svc.cluster.local # cluster internal host
      subsets:
      - name: v1
        labels:
          version: v1
      - name: v2
        labels:
          version: v2
    

    但也可能是您希望将流量路由到集群外部目的地。在这种情况下,destination.host 将是一个外部 fqdn,就像文档中的这个例子一样:

    apiVersion: networking.istio.io/v1beta1
    kind: ServiceEntry
    metadata:
      name: external-svc-wikipedia
    spec:
      hosts:
      - wikipedia.org
      location: MESH_EXTERNAL
      ports:
      - number: 80
        name: example-http
        protocol: HTTP
      resolution: DNS
    ---
    apiVersion: networking.istio.io/v1beta1
    kind: VirtualService
    metadata:
      name: my-wiki-rule
    spec:
      hosts:
      - wikipedia.org
      http:
      - timeout: 5s
        route:
        - destination:
            host: wikipedia.org
    

    将其视为“我想将流量从 HOST_FROM 路由到 HOST_TO”,其中

    • HOST_FROM 是spec.hostspec.hosts
    • HOST_TO 是destination.host

    两者都可以在 kubernetes 集群内部或外部。

    所以回答你所有的问题:

    这取决于:如果你想从/到集群内部流量路由,你将使用 kubernetes 服务 fqdn。对于集群外部流量,您将使用外部目标 fqdn。

    我强烈建议阅读 VirtualServiceDestinationRule 的文档,您可以在其中看到几个示例和解释。

    【讨论】:

      猜你喜欢
      • 2012-05-16
      • 2020-07-04
      • 1970-01-01
      • 2019-12-16
      • 2012-09-22
      • 1970-01-01
      • 2021-08-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多