首页 > 解决方案 > `ServiceEntry` 可以仅应用于一项服务吗?

问题描述

我们有一个带有 Istio 的集群,但是有一个条件,我找不到如何满足。

我们需要其中一项服务在网格内也有一定的限制,并与一个外部端点通信。通过Sidecar对象,我应该能够在内部设置限制,但我不知道如何限制到一个外部端点。

我也可以在对象中设置外部端点Sidecar,但无论如何我都必须创建一个ServiceEntry,在这种情况下,所有服务都可以与该外部端点通信。

似乎我需要ServiceEntry为一项特定服务设置一个,但这是不可能的。有没有其他方法可以实现这一目标?

标签: kubernetesistio

解决方案


在 GitHub 上问了这个问题;对于 Istio 团队来说,实现这一点的唯一方法是将服务放在不同的命名空间中,并通过参数ServiceEntry使其仅应用于该命名空间中的工作负载。exportTo

ServiceEntry看起来像这样:

apiVersion: networking.istio.io/v1beta1
kind: ServiceEntry
metadata:
  name: se-demo
spec:
  exportTo:
  - .                 # with ".", we are saying the ServiceEntry to only apply to the workloads in the same namespace.
  hosts:
  - www.google.com
  location: MESH_EXTERNAL
  ports:
  - name: https
    number: 443
    protocol: HTTPS
  resolution: DNS

推荐阅读