是否可以通过两个命名空间进行过滤 和 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/