【问题标题】:egress policy not getting applied with kubernetes 1.9Kubernetes 1.9 未应用出口策略
【发布时间】:2018-11-08 16:44:05
【问题描述】:

我想拒绝所有出口流量。所以我创建了这个网络策略

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

然后我将它应用到命名空间

kubectl -n pps-api-gateway-ci apply -f ~/Documents/networkpolicy.yaml

为了测试这一点,我确实描述了网络策略

    kubectl -n pps-api-gateway-ci describe networkpolicy
    Name:         default-deny
    Namespace:    pps-api-gateway-ci
    Created on:   2018-05-29 13:50:52 -0700 PDT
    Labels:       <none>
    Annotations:  kubectl.kubernetes.io/last-applied-configuration= 
   {"apiVersion":"networking.k8s.io/v1","kind":"NetworkPolicy","metadata": 
   {"annotations":{},"name":"default-deny","namespace":"pps-api-gateway- 
   ci"},"spec"...
   Spec:
      PodSelector:     <none> (Allowing the specific traffic to all pods in this 
    namespace)
      Allowing ingress traffic:
        <none> (Selected pods are isolated for ingress connectivity)
       Allowing egress traffic:
        <none> (Selected pods are isolated for egress connectivity)
       Policy Types: Egress

然后我登录到那个容器

ping www.google.com

PING www.google.com (216.58.217.100): 56 data bytes
64 bytes from 216.58.217.100: icmp_seq=0 ttl=46 time=2.552 ms
64 bytes from 216.58.217.100: icmp_seq=1 ttl=46 time=1.835 ms
64 bytes from 216.58.217.100: icmp_seq=2 ttl=46 time=1.487 ms
64 bytes from 216.58.217.100: icmp_seq=3 ttl=46 time=2.523 ms
64 bytes from 216.58.217.100: icmp_seq=4 ttl=46 time=1.607 ms
64 bytes from 216.58.217.100: icmp_seq=5 ttl=46 time=1.480 ms

如果应用了我的出口政策,我应该无法 ping。

我正在使用 Kubernetes 1.9.6 版本

【问题讨论】:

  • 您能否添加有关您正在使用的网络解决方案以及如何安装它的信息?

标签: kubernetes


【解决方案1】:

来自official documentation

网络策略由网络插件实施,因此您必须使用支持 NetworkPolicy 的网络解决方案 - 只需创建无需控制器即可实施的资源没有效果

许多网络插件,包括CalicoWeave Net,支持使用Network Policies,但不支持Flannel

【讨论】:

  • 我们已经在 kube-system 命名空间中有网络插件
猜你喜欢
  • 2020-01-01
  • 2020-03-04
  • 2019-02-04
  • 2022-01-13
  • 2021-10-03
  • 2020-11-15
  • 2019-01-21
  • 2022-11-14
  • 2018-10-10
相关资源
最近更新 更多