gpt4 book ai didi

kubernetes - 如何将 Pod 导出流量限制为仅限外部

转载 作者:行者123 更新时间:2023-12-04 17:09:09 25 4
gpt4 key购买 nike

我需要限制流向外部目的地的 pod 导出流量。 Pod 应该能够访问互联网上的任何目的地,并且应该拒绝所有集群内部目的地。

这是我尝试过的,但没有通过验证:

apiVersion: networking.istio.io/v1beta1
kind: Sidecar
metadata:
name: test
spec:
workloadSelector:
labels:
k8s-app: mypod

outboundTrafficPolicy:
mode: REGISTRY_ONLY

egress:
- hosts:
- 'default/*'
apiVersion: networking.istio.io/v1alpha3
kind: ServiceEntry
metadata:
name: all-external

spec:
location: MESH_EXTERNAL
resolution: DNS
hosts:
- '*'
ports:
- name: http
protocol: HTTP
number: 80
- name: https
protocol: TLS
number: 443

Istio 1.11.4

最佳答案

我是使用 NetworkPolicy 完成的。允许流量到 kubernetes 和 istio 相关服务(可能不仅基于命名空间更严格):

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: myapp-eg-system

spec:
podSelector:
matchLabels:
app: myapp

policyTypes:
- Egress

egress:
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: kube-system
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: istio-system

允许除集群网络 IP 空间之外的任何内容:

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: myapp-eg-app

spec:
podSelector:
matchLabels:
app: myapp

policyTypes:
- Egress

egress:
- to:
# Restrict to external traffic
- ipBlock:
cidr: '0.0.0.0/0'
except:
- '172.0.0.0/8'

- podSelector:
matchLabels:
app: myapp

ports:
- protocol: TCP

关于kubernetes - 如何将 Pod 导出流量限制为仅限外部,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69839229/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com