是否可以只允许出口流量到达特定的服务?这是我天真的尝试:
kind: NetworkPolicy
metadata:
name: default-deny-all-egress
namespace: default
spec:
podSelector: {}
egress:
- ports:
- protocol: TCP
port: 53
- protocol: UDP
port: 53
to:
- podSelector:
matchLabels:
k8s-app: kube-dns
policyTypes:
- Egress发布于 2021-03-03 00:04:51
不,据我所知,您只能使用podSelector来完成此操作。但是,如果您有访问集群的权限,我认为您仍然可以手动为所需的pods添加其他标签,并使用podSelector
Create egress policies为你提供了一个很好的NetworkPolicy结构模板。以下策略允许pod出站流量到达同一命名空间中与pod选择器匹配的其他pod。
kind: NetworkPolicy
apiVersion: networking.k8s.io/v1
metadata:
name: allow-egress-same-namespace
namespace: default
spec:
podSelector:
matchLabels:
color: blue
egress:
- to:
- podSelector:
matchLabels:
color: red
ports:
- port: 80我知道您可以使用namespaceSelector作为入口,如下所示。不确定您是否可以将其与egress一起使用-尚未尝试。但是要访问其他名称空间中的pod,您应该以某种方式将其指向配置中
namespaceSelector:
matchLabels:
shape: squarehttps://stackoverflow.com/questions/66423222
复制相似问题