kubernetes K8s默认网络策略,拒绝还是允许?

gijlo24d  于 2023-01-20  发布在  Kubernetes
关注(0)|答案(1)|浏览(162)

我的系统包含网络策略,但我对其中一个有疑问。我无法测试它。我只能打印出配置并“想象”它的功能。

kubectl get networkpolicies
=>   
...
spec:
    ingress:
    - from:
      - podSelector: {}
    podSelector: {}
    policyTypes:
    - Ingress

我不确定上面的那个是拒绝来自其他名称空间的所有流量,还是相反地允许所有流量。
https://kubernetes.io/docs/concepts/services-networking/network-policies/章“默认策略”我会说它允许所有流量,但我不太确定...
“描述”并没有真正帮助我:

kubectl describe networkpolicies
=>
...
Spec:
  PodSelector:     <none> (Allowing the specific traffic to all pods in this namespace)
  Allowing ingress traffic:
    To Port: <any> (traffic allowed to all ports)
    From:
      PodSelector: <none>
  Not affecting egress traffic
  Policy Types: Ingress

你觉得怎么样?谢谢!

6kkfgxo0

6kkfgxo01#

以下netpol将允许所有入口流量:

---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: allow-all-ingress
spec:
  podSelector: {}
  ingress:
  - {}
  policyTypes:
  - Ingress

这将拒绝所有出口和入口流量:

---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: default-deny-all
spec:
  podSelector: {}
  policyTypes:
  - Ingress
  - Egress

相关问题