如果 VirtualService 只是服务的普通代理,我们是否应该定义它?

Should we define VirtualService if it is just a plain proxy to Service?

我有以下虚拟服务,其 hosts 映射 (backend) 与 host 目标 (backend) 相同。我认为这是多余的,因为我们可以直接访问 K8S Service

apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
  name: backend
  namespace: default
spec:
  hosts:
  - backend
  http:
  - route:
    - destination:
        host: backend

我的理解对吗?如果不是,是否更好地为每个 Service 定义 VirtualService

你说得对,你的虚拟服务是多余的,不需要。然而,最好的做法是从一开始就为您的服务定义虚拟服务,特别是如果您计划在未来使用 istio 流量管理功能。这在文档 this section 的最后一段中提到。