首页 > 解决方案 > 如何通过运营商网关路由出口流量

问题描述

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

这个想法是只允许来自 test-pod 的白名单域用于出口。我已经应用了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

从 testpod 何时curl -v https://google.com被阻止并且允许其他 url。根据运营商的自述文件,我还需要一个默认拒绝出口 K3s 策略,因此我也应用了它。但在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 网关的出口流量?

标签: kuberneteskubernetes-podkubernetes-networkpolicykubernetes-operatorkubernetes-networking

解决方案


将此答案发布为社区 wiki,随时编辑和扩展。


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

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


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

因为默认情况下,来自启用 Istio 的 pod 的所有出站流量都被重定向到其 sidecar 代理,集群外部 URL 的可访问性取决于代理的配置。默认情况下,Istio 将 Envoy 代理配置为传递未知服务的请求。虽然这为开始使用 Istio 提供了一种便捷的方式,但通常更可取的是配置更严格的控制。

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


推荐阅读