我必须在我的一个豆荚中配置一个静态IP,因为远程服务(在集群之外)需要可信的IP白名单。
我跟踪了Google提供的文档:
https://cloud.google.com/nat/docs/overview?hl=es-419
https://cloud.google.com/kubernetes-engine/docs/how-to/ip-masquerade-agent
但是,当尝试在我的GKE集群中使用Google服务配置出口流量时,加上使用ip-masq-agent伪装,我开始在访问集群之外的远程服务时遇到超时和问题。
我的集群在1.19.10-gke.1600版本中。
我尝试了这些配置文件,结果如下:
resyncInterval: 60s结果:
Chain IP-MASQ (2 references)
target prot opt source destination
RETURN all -- anywhere 10.0.0.0/8 /* ip-masq-agent: local traffic is not sub
ject to MASQUERADE */
RETURN all -- anywhere 172.16.0.0/12 /* ip-masq-agent: local traffic is not sub
ject to MASQUERADE */
RETURN all -- anywhere 192.168.0.0/16 /* ip-masq-agent: local traffic is not sub
ject to MASQUERADE */
MASQUERADE all -- anywhere anywhere /* ip-masq-agent: outbound traffic is sub
ject to MASQUERADE (must be last in chain) */这些服务一直使用错误的IP。
resyncInterval: 60s
masqLinkLocal: true
Chain IP-MASQ (2 references)
target prot opt source destination
RETURN all -- anywhere 169.254.0.0/16 /* ip-masq-agent: local traffic is not sub
ject to MASQUERADE */
RETURN all -- anywhere 10.0.0.0/8 /* ip-masq-agent: local traffic is not sub
ject to MASQUERADE */
RETURN all -- anywhere 172.16.0.0/12 /* ip-masq-agent: local traffic is not sub
ject to MASQUERADE */
RETURN all -- anywhere 192.168.0.0/16 /* ip-masq-agent: local traffic is not sub
ject to MASQUERADE */
MASQUERADE all -- anywhere anywhere /* ip-masq-agent: outbound traffic is sub
ject to MASQUERADE (must be last in the chain) */同样的效果,我的外部服务得到了错误的IP。
nonMasqueradeCIDRs:
- 0.0.0.0/0
resyncInterval: 60s
masqLinkLocal: true
Chain IP-MASQ (2 references)
target prot opt source destination
RETURN all -- anywhere anywhere /* ip-masq-agent: local traffic is not sub
ject to MASQUERADE */
MASQUERADE all -- anywhere anywhere /* ip-masq-agent: outbound traffic is sub
ject to MASQUERADE (must be last in the chain) */这看起来更好,因为外部服务接收到了正确的IP,但是我会遇到连接问题和超时。
这是我的NAT配置:
NAT mapping
- High availability: Yes
- Source subnets & IP ranges: All subnets' primary and secondary IP ranges
- NAT IP addresses: static-egress-ip XXX.XXX.XXX.XXX我没什么主意了,谁能给我点建议吗?
响应到这里之后,我更新了配置文件,以在google文档之后添加ips,文件如下:
nonMasqueradeCIDRs:
- 10.0.0.0/8
- 172.16.0.0/12
- 192.168.0.0/16
- 100.64.0.0/10
- 192.0.0.0/24
- 192.0.2.0/24
- 192.88.99.0/24
- 198.18.0.0/15
- 198.51.100.0/24
- 203.0.113.0/24
- 240.0.0.0/4
resyncInterval: 60s
masqLinkLocal: true在iptables中这样做的结果是:
Chain IP-MASQ (2 references)
target prot opt source destination
RETURN all -- anywhere 10.0.0.0/8 /* ip-masq-agent: local traffic is not sub
ject to MASQUERADE */
RETURN all -- anywhere 172.16.0.0/12 /* ip-masq-agent: local traffic is not sub
ject to MASQUERADE */
RETURN all -- anywhere 192.168.0.0/16 /* ip-masq-agent: local traffic is not sub
ject to MASQUERADE */
RETURN all -- anywhere 100.64.0.0/10 /* ip-masq-agent: local traffic is not sub
ject to MASQUERADE */
RETURN all -- anywhere 192.0.0.0/24 /* ip-masq-agent: local traffic is not sub
ject to MASQUERADE */
RETURN all -- anywhere 192.0.2.0/24 /* ip-masq-agent: local traffic is not sub
ject to MASQUERADE */
RETURN all -- anywhere 192.88.99.0/24 /* ip-masq-agent: local traffic is not sub
ject to MASQUERADE */
RETURN all -- anywhere 198.18.0.0/15 /* ip-masq-agent: local traffic is not sub
ject to MASQUERADE */
RETURN all -- anywhere 198.51.100.0/24 /* ip-masq-agent: local traffic is not sub
ject to MASQUERADE */
RETURN all -- anywhere 203.0.113.0/24 /* ip-masq-agent: local traffic is not sub
ject to MASQUERADE */
RETURN all -- anywhere 240.0.0.0/4 /* ip-masq-agent: local traffic is not sub
ject to MASQUERADE */
MASQUERADE all -- anywhere anywhere /* ip-masq-agent: outbound traffic is sub
ject to MASQUERADE (must be last in chain) */但是,如果我运行一个curl checkip.amazonaws.com来查看节点正在使用什么IP,我会得到一个与我的NAT云配置中定义的IP不同的IP,外部服务拒绝来自我的集群的非信任请求。
发布于 2021-06-11 02:02:14
最后我们能够诊断出这个问题。我们的集群创建于一段时间前,当时GCP不支持私有集群,因此我们的集群是公开的。
每个节点都有一个公共的临时IP,因此NAT规则被忽略。
解决方案是设置一个具有静态IP的节点,而不是临时的,并配置需要可信的auth始终部署在该特定节点上的工作负载。这不是一个完美的解决方案,而是我们可以迅速解决问题的方法。
真正的解决方案是迁移到私有集群并配置NAT,但遗憾的是,GCP不支持从公共集群迁移到私有集群。唯一的选择是创建一个新的集群--将工作负载迁移到新集群,这是我们需要在短期内执行的进程。
也许这是一个测试自动驾驶仪的好时机,因为它也不支持自动迁移。
发布于 2021-06-09 05:16:28
您似乎已经将nonMasqueradeCIDRs:设置为0.0.0.0/0,从而防止了所有CIDR通信量的伪装,因此要解决此问题,在配置文件中使用Defaut非伪装目标段1中提到的in更新非伪装CIDR: key,如下所示。
非伪装:
还请注意,截图中提到的IP不是错误的ip,但那些是RFC 1918/link-local保留的范围,即IPs 10.0.0.0/8、172.16.0.0/12 192.168.0.0/16保留给RFC 1918,ip范围169.254.0.0/16保留给链接-本地,并且这些ip是不可伪装的,因此这些ip是用描述‘ip-masq-代理:本地流量不受伪装’2的描述显示的。
你好,安布。
https://serverfault.com/questions/1065879
复制相似问题