Kubernetes 从集群内部使用Istio VirtualService

Kubernetes 从集群内部使用Istio VirtualService,kubernetes,istio,Kubernetes,Istio,我无法使用Kubernetes服务,因为我需要重试虚拟服务功能。如何从pods访问VirtualService 如果我通过网关使用VirtualService: Pod->Kubernetes服务->Istio网关->虚拟服务 然后,由于某种原因,locality平衡功能不起作用。我猜您有这样的功能: apiVersion: networking.istio.io/v1alpha3 kind: VirtualService metadata: name: review-external sp

我无法使用Kubernetes服务,因为我需要
重试
虚拟服务功能。如何从pods访问VirtualService

如果我通过网关使用VirtualService:
Pod
->
Kubernetes服务
->
Istio网关
->
虚拟服务

然后,由于某种原因,
locality
平衡功能不起作用。

我猜您有这样的功能:

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
在这种情况下,您可以使用
VirtualService
对象中的
gateways
列表进行此操作

对于文档:

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

资料来源:

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

[...]
  gateways:
  - mygateway
  - mesh
  http:
[...]
或者,您可以创建第二个
VirtualService
,而不使用
gateways
列表,使其默认为
mesh
(或者如果您希望声明,则仅将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,但集群内部的流量仍然可以到达。

您使用的是什么平台/结构?请提供您的配置文件-virtualservice定义、网关等。我已尝试过此操作,但未保留位置平衡。你有没有试着和当地人进行点对点的交流?如果您已经尝试过,并且它是“按设计”工作的,我将创建一个配置的简化示例,也许我遗漏了一些东西。感谢您提供的详细答案。我使用它与两个vs进行pod-to-pod通信,以不同方式处理集群内的流量,但我的用例不需要负载平衡。您可以通过vs向请求添加标头,以确认是否使用了该标头。