docker - 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_ADMIN
和NET_RAW
功能(in containers[i].securityContext.capabilities.add
)就足够了。示例 json 切片:
"spec": {
"hostNetwork": true,
"containers": [{
"name": "netadmin",
"securityContext": {"capabilities": { "add": ["NET_ADMIN", "NET_RAW"] } }
我不确定这些天特权模式是否与操纵主机的 iptables 有关。
推荐阅读
- javascript - 检查两个数字是正数还是负数
- php - Web 表单将发送到我的共享主机帐户上的 STMP 电子邮件地址,但不会发送到 gmail、yahoo 等
- javascript - 媒体查询移动视口没有响应
- javafx - JavaFx MediaPlayer 无法播放我通过 ffmpeg 转换的 mp3 和 m4a 文件
- ios - Swift:如何动态创建 FDWaveformview
- c - 在 R 中从 C 安装库 - Windows 10 - 文件格式错误
- windows - IIS 401.3 与 Windows 身份验证 2016
- r - R中地理空间点的水平和垂直距离?
- c# - 字符串连接 C# 与类列表
- c# - GridView 不显示在网页上