从集群内部使用 Istio VirtualService

时间:2021-01-08 10:04:57

标签: kubernetes istio

我无法使用 Kubernetes 服务,因为我需要 retry VirtualService 功能。如何从 Pod 访问 VirtualService?

如果我通过网关使用 VirtualService: Pod -> Kubernetes service -> Istio Gateway -> Virtual service 然后由于某种原因locality平衡功能不起作用。

1 个答案:

答案 0 :(得分:1)

我猜你有这样的东西:

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: review-external
spec:
  hosts:
  - "*.example.com"
  gateways:
  - mygateway
  http:
    route:
    - destination:
        host: reviews.prod.svc.cluster.local
        subset: v2
      weight: 25

在这种情况下,您可以使用 gateways 对象中的 VirtualService 列表。

对于文档:

<块引用>

如果省略此字段,将使用默认网关(mesh),这会将规则应用于网格中的所有边车。如果提供了网关名称列表,则规则将仅适用于网关。要将规则同时应用于网关和边车,请将网格指定为网关名称之一。

来源: https://istio.io/latest/zh/docs/reference/config/networking/virtual-service/#VirtualService

所以你有两个选择。您可以提及 mesh 作为网关之一:

[...]
  gateways:
  - mygateway
  - mesh
  http:
[...]

或者您可以在没有 VirtualService 列表的情况下创建第二个 gateways,使其默认为 mesh(或者如果您想声明性地仅提及网格作为网关)。 spec.hosts 字段必须包含 destination.host 中提到的主机。

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: review-mesh-internal
spec:
  hosts:
  - "reviews.prod.svc.cluster.local" # must be the kubernetes service host as below
  gateways:
  - mesh #optional since it's the default
  http:
    route:
    - destination:
        host: reviews.prod.svc.cluster.local
        subset: v1
      weight: 100

这带来了优势,您可以从集群外部与从集群内部不同地路由流量。以维护为例,用户流量不应到达特定 Pod,但来自集群内部的流量仍应能够到达。