kubernetes - 如何通过运营商网关路由出口流量
问题描述
我已经在我的 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 网关的出口流量?
解决方案
将此答案发布为社区 wiki,随时编辑和扩展。
Istio
可以用作这种情况的解决方案。这是一个开源项目,因此不需要为其使用付费。
Istio 有一个非常好的文档,其中包含如何实现不同结果的示例。istio
与运营商相比,文档要好得多monzo
+许多大公司都使用它,因此它是可靠的解决方案。
访问外部服务及其工作原理:
因为默认情况下,来自启用 Istio 的 pod 的所有出站流量都被重定向到其 sidecar 代理,集群外部 URL 的可访问性取决于代理的配置。默认情况下,Istio 将 Envoy 代理配置为传递未知服务的请求。虽然这为开始使用 Istio 提供了一种便捷的方式,但通常更可取的是配置更严格的控制。
请查找istio
与您的目标相同的文档和涵盖的用例:
推荐阅读
- python - 如何在同一标签下绘制整个 Pandas DataFrame?
- python-3.x - 如何有效地使用 Django 查询和 Q 过滤查询集中的每个对象并为查询集中的每个唯一字段返回 1 个字段值
- ruby - 如何防止 peek 方法将读取光标向前移动?
- html-table - 表内的 Bootstrap 4 datetimepicker 设计不正确
- python - Pandas 使用多个条件在列中分配值:
- java - 使用 java nullpointerexception 显示背景图像
- mysql - 在 bash 中获取 MySQL 输出
- django-rest-framework - 脚本的哪一部分使 JSON API 作为 Django Rest Framework 中的对象数组返回?
- c# - 在 ControlTemplate 触发器中获取 WPF ContextMenu 打开方向
- gitlab - Gitlab-CI 非零退出成功