ip-masq-agent
weight: 87
title: IP 伪装代理
date: “2022-05-21T00:00:00+08:00”
type: book
本文将讲述如何配置和启用
创建ip-masq-agent
要创建
kubectl create -f https://raw.githubusercontent.com/kubernetes-incubator/ip-masq-agent/master/ip-masq-agent.yaml
关于
在大多数情况下,默认的一套规则应该是足够的;但是,如果内置的规则不适用于您的集群,您可以创建并应用
nonMasqueradeCIDRs:
- 10.0.0.0/8
resyncInterval: 60s
注意:重要的是,该文件被命名为
运行下列命令将
kubectl create configmap ip-masq-agent --from-file=config --namespace=kube-system
这将会更新
iptables -t nat -L IP-MASQ-AGENT
Chain IP-MASQ-AGENT (1 references)
target prot opt source destination
RETURN all -- anywhere 169.254.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/8 /* ip-masq-agent: cluster-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
默认情况下,本地链路范围(169.254.0.0/16)也由
nonMasqueradeCIDRs:
- 10.0.0.0/8
resyncInterval: 60s
masqLinkLocal: true
IP 伪装代理用户指南
关键术语
-
NAT(网络地址转换)
是一种通过修改
IP 头中的源和/ 或目标地址信息来将一个IP 地址重映射到另一个IP 地址的方法。通常由执行IP 路由的设备完成。 -
Masquerading(伪装)
NAT 的一种形式,通常用于执行多个地址转换,其中多个源IP 地址被掩盖在单个地址之后,通常是由某设备进行IP 路由。在kubernetes 中,这是Node 的IP 地址。 -
CIDR(无类域内路由选择)
基于可变长度子网掩码,允许指定任意长度的前缀。
CIDR 引入了一种新的IP 地址表示方法,现在通常被称为CIDR 表示法,将地址或路由前缀的比特位数作为后缀,例如192.168.2.0/24 。 -
本地链路
本地链路地址是仅能在主机连接的网段或广播域内进行有效通信的网络地址。
IPv4 的链路本地地址在CIDR 表示法定义的地址块是169.254.0.0/16 。

代理的配置文件必须使用
- nonMasqueradeCIDRs:使用 CIDR 表示法指定的非伪装范围的字符串列表。
- masqLinkLocal:一个布尔值(true/false
) ,表示是否将流量伪装成本地链路前缀169.254.0.0/16 。默认为false 。 - resyncInterval:代理尝试从磁盘重新加载配置的时间间隔。例如 ’30s’ 其中 ‘s’ 是秒
, ’ms’ 是毫秒等…
到
iptables -t nat -L IP-MASQ-AGENT
RETURN all -- anywhere 169.254.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/8 /* ip-masq-agent: cluster-local traffic should not be subject to MASQUERADE */ ADDRTYPE match dst-type !LOCAL
RETURN all -- anywhere 172.16.0.0/12 /* ip-masq-agent: cluster-local traffic should not be subject to MASQUERADE */ ADDRTYPE match dst-type !LOCAL
RETURN all -- anywhere 192.168.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
默认情况下,在