如何通过运营商网关路由出口流量

问题描述

我已经在我的 ubuntu 机器上部署了 egress-operator,并且这个运营商在内部使用 envoy 代理来控制出口流量。

这个想法是只允许来自 test-pod 的 whitelisted domains 用于出口。我已经应用了此运营商的外部服务 yaml,但它给出了相反的结果,而不是允许 google.com 阻止 google.com 并允许其他调用。我可能做错了什么?

我的 ExternalService.yaml

    apiVersion: egress.monzo.com/v1
    kind: ExternalService
    Metadata:
      name: google
    spec:
      dnsName: google.com
      # optional,defaults to false,instructs dns server to rewrite queries for dnsName
      hijackDns: true
      ports:
      - port: 80
      - port: 443
        protocol: TCP
      minReplicas: 1
      maxReplicas: 3

我的 testpod.yaml

apiVersion: v1
kind: Pod
Metadata:
  name: Nginx
  namespace: testNs-system
  labels:
    egress.monzo.com/allowed-gateway: google
spec:
  containers:
  - image: Nginx:1.14.2
    command:
      - "sleep"
      - "604800"
    imagePullPolicy: IfNotPresent
    name: Nginx
  restartPolicy: Always

curl -v https://google.com 被阻止并且允许其他 url 时来自 testpod。根据操作员的自述文件,我需要一个 defaut-deny-Egress K3s policy also,因此我也应用了它。但在 default-deny-Egress 政策之后,包括 google.com(列入白名单的)在内的所有出口调用都被 testpod 阻止。

Default-Deny-All-Egress.yaml

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
Metadata:
  name: default-deny-all-egress
  namespace: testNs-system
spec:
  podSelector:
    matchLabels:
      app: Nginx
      egress.monzo.com/allowed-gateway: google
  policyTypes:
  - Egress
  egress: []

如何从 egress-operator pod 或 egress-operator gateway 路由出口流量?

解决方法

将此答案作为社区 Wiki 发布,您可以随意编辑和扩展。


Istio 可以用作这种情况的解决方案。这是一个开源项目,因此不需要为其使用付费。

Istio 有一个非常好的文档,其中包含如何实现不同结果的示例。与 istio 运算符相比,monzo 的文档要好得多 + 许多大公司都在使用它,因此它是可靠的解决方案。


访问外部服务及其工作原理:

因为来自支持 Istio 的 pod 的所有出站流量都被重定向 默认情况下到它的边车代理,可访问性之外的 URL cluster 取决于代理的配置。默认情况下,Istio 配置 Envoy 代理以传递对未知的请求 服务。虽然这提供了一种方便的入门方式 Istio,通常最好配置更严格的控制。

请找到与您目标相同的 istio 文档和涵盖的用例: