云上有各种复杂的网络互通场景,例如:
1. 容器要能访问外网
2. 容器要能访问用户 IDC
3. 容器要能访问云上其他 VPC
本文将以外网访问为例介绍 TKE 当前的实现机制。
当前的实现是让容器访问外网的数据包 SNAT 为节点 IP 出去,所以容器具备外网访问能力依赖于节点具备外网访问能力。
可以通过给节点分配外网 IP,绑定了弹性公网 IP,绑定 NAT 网关等方式让节点具备外网访问能力。
当前的实现是容器访问集群网络和 VPC 网络的不走 SNAT,访问其他网段都走 SNAT。
具体 iptables 规则的下发依赖于 ip-masq-agent。
配置示例:
VPC 网络:10.0.0.0/16
集群网络:172.18.0.0/16
# kubectl get cm -n kube-system ip-masq-agent-config -o yaml
apiVersion: v1
data:
config: '{"NonMasqueradeCIDRs":["172.18.0.0/16","10.0.0.0/16"],"MasqLinkLocal":true,"ResyncInterval":"1m0s"}'
kind: ConfigMap
metadata:
name: ip-masq-agent-config
namespace: kube-system
......
上述配置的意思是:访问目的网络 10.0.0.0/16 和 172.18.0.0/16 不做 SNAT,其他网段都做 SNAT,不对网段 169.254.0.0/16 做特殊处理,同步周期为1分钟。
# iptables -t nat -L IP-MASQ-AGENT
Chain IP-MASQ-AGENT (1 references)
target prot opt source destination
RETURN all -- anywhere 172.18.0.0/16 /* ip-masq-agent: cluster-local traffic should not be subject to MASQUERADE */ ADDRTYPE match dst-type !LOCAL
RETURN all -- anywhere 10.0.0.0/16 /* ip-masq-agent: cluster-local traffic should not be subject to MASQUERADE */ ADDRTYPE match dst-type !LOCAL
MASQUERADE all -- anywhere anywhere /* ip-masq-agent: outbound traffic should be subject to MASQUERADE (this match must come after cluster-local CIDR matches) */ ADDRTYPE match dst-type !LOCAL
弹性公网 IP:https://cloud.tencent.com/document/product/213/5733
NAT 网关:https://cloud.tencent.com/document/product/215/20079
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有