gpt4 book ai didi

Kubernetes 网络策略来过滤命名空间和 pod 的标签

转载 作者:行者123 更新时间:2023-12-04 18:59:10 24 4
gpt4 key购买 nike

是否可以通过两个命名空间进行过滤 pod 的标签?

文档中的示例位于 https://kubernetes.io/docs/user-guide/networkpolicies/#the-networkpolicy-resource

 - from:
- namespaceSelector:
matchLabels:
project: myproject
- podSelector:
matchLabels:
role: frontend

表示允许与 role=frontend 的 pod 进行通信 来自 namespace myproject .

有什么办法可以把那个“或”变成“和”?

最佳答案

Kubernetes 1.11 及更高版本支持将 podSelector 和 namespaceSelector 与逻辑 AND 组合:

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: database.postgres
namespace: database
spec:
podSelector:
matchLabels:
app: postgres
ingress:
- from:
- namespaceSelector:
matchLabels:
namespace: default
podSelector:
matchLabels:
app: admin
policyTypes:
- Ingress

在此处查看更多详细信息: https://medium.com/@reuvenharrison/an-introduction-to-kubernetes-network-policies-for-security-people-ba92dd4c809d/#f416

关于Kubernetes 网络策略来过滤命名空间和 pod 的标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42228852/

24 4 0