首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在GKE上使用NAT + IP伪装时对Cloud和其他外部服务的超时

在GKE上使用NAT + IP伪装时对Cloud和其他外部服务的超时
EN

Server Fault用户
提问于 2021-06-06 14:29:59
回答 2查看 463关注 0票数 1

我必须在我的一个豆荚中配置一个静态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版本中。

我尝试了这些配置文件,结果如下:

代码语言:javascript
复制
resyncInterval: 60s

结果:

代码语言:javascript
复制
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。

代码语言:javascript
复制
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。

代码语言:javascript
复制
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配置:

代码语言:javascript
复制
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,文件如下:

代码语言:javascript
复制
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中这样做的结果是:

代码语言:javascript
复制
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,外部服务拒绝来自我的集群的非信任请求。

EN

回答 2

Server Fault用户

回答已采纳

发布于 2021-06-11 02:02:14

最后我们能够诊断出这个问题。我们的集群创建于一段时间前,当时GCP不支持私有集群,因此我们的集群是公开的。

每个节点都有一个公共的临时IP,因此NAT规则被忽略。

解决方案是设置一个具有静态IP的节点,而不是临时的,并配置需要可信的auth始终部署在该特定节点上的工作负载。这不是一个完美的解决方案,而是我们可以迅速解决问题的方法。

真正的解决方案是迁移到私有集群并配置NAT,但遗憾的是,GCP不支持从公共集群迁移到私有集群。唯一的选择是创建一个新的集群--将工作负载迁移到新集群,这是我们需要在短期内执行的进程。

也许这是一个测试自动驾驶仪的好时机,因为它也不支持自动迁移。

票数 0
EN

Server Fault用户

发布于 2021-06-09 05:16:28

您似乎已经将nonMasqueradeCIDRs:设置为0.0.0.0/0,从而防止了所有CIDR通信量的伪装,因此要解决此问题,在配置文件中使用Defaut非伪装目标段1中提到的in更新非伪装CIDR: key,如下所示。

非伪装:

  • 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
  • 10.0.0.0/8

还请注意,截图中提到的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的描述显示的。

1

2

你好,安布。

票数 1
EN
页面原文内容由Server Fault提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://serverfault.com/questions/1065879

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档