K8S iptables 与 Pod 内容器之间的关系



>我已经在容器中启用了特权模式并向其添加了规则,

iptables -N udp2rawDwrW_191630ce_C0
iptables -F udp2rawDwrW_191630ce_C0
iptables -I udp2rawDwrW_191630ce_C0 -j DROP
iptables -I INPUT -p tcp -m tcp --dport 4096 -j udp2rawDwrW_191630ce_C0

kt exec容器并使用iptables --table filter -L,我可以看到添加的规则。

/ # iptables --table filter -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination
udp2rawDwrW_191630ce_C0  tcp  --  anywhere             anywhere             tcp dpt:4096
Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
Chain udp2rawDwrW_191630ce_C0 (1 references)
target     prot opt source               destination
DROP       all  --  anywhere             anywhere

当我登录到容器所在的节点并运行sudo iptalbes --table filter -L时,我看不到相同的结果。

我认为默认情况下previleged被丢弃,因为容器可能会利用它来更改节点中的iptables之类的内容,但是看起来并非如此。

所以我的问题是"K8S iptables 和 Pod 内的容器之间的关系是什么"和"为什么我们阻止用户在没有privileged字段的情况下修改容器的 iptables"?

如果你想操纵节点的iptables,那么你肯定需要把pod放在主机的网络上(hostNetwork: true在pod的spec内(。之后授予容器NET_ADMINNET_RAW能力(containers[i].securityContext.capabilities.add(就足够了。 示例 JSON 切片:

"spec": {
"hostNetwork": true,
"containers": [{
"name": "netadmin",
"securityContext": {"capabilities": { "add": ["NET_ADMIN", "NET_RAW"] } }

我不确定特权模式是否与这些天操纵主机的iptables有关。

最新更新