Kubernetes网络策略可同时过滤名称空间和Pod的标签

Ada*_*ski 5 kubernetes

是否可以同时按名称空间 pod的标签进行过滤?

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

 - from:
 - namespaceSelector:
    matchLabels:
     project: myproject
 - podSelector:
    matchLabels:
     role: frontend
Run Code Online (Sandbox Code Playgroud)

表示允许与role=frontend 来自的广告连播进行通讯namespace myproject

有什么办法可以将“或”更改为“与”?

Mar*_*ark 6

Kubernetes 1.11及以上版本支持通过逻辑AND组合podSelector和namespaceSelector:

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
Run Code Online (Sandbox Code Playgroud)

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


Raf*_*esp 2

编辑:这已在这里实现:https ://github.com/kubernetes/kubernetes/pull/60452

目前还没有办法从另一个命名空间中选择某个 pod。有一个未解决的问题https://github.com/kubernetes/kubernetes/issues/50451