kubernetes - 谷歌 Kubernetes 引擎和 VPN
问题描述
我正在使用 Google Kubernetes Engine 部署一些需要连接到本地数据库的应用程序。为此,我配置了一个 VPN 隧道并创建了一个 VPC。
然后,我创建了一个使用该 VPC 的 GKE 集群(1 个节点),我可以通过连接到该节点并尝试 ping 数据库服务器来确认可以访问数据库
~ $ sudo toolbox ping 10.197.100.201
Spawning container root-gcr.io_google-containers_toolbox-20180309-00 on
/var/lib/toolbox/root-gcr.io_google-containers_toolbox-20180309-00.
Press ^] three times within 1s to kill container.
PING 10.197.100.201 (10.197.100.201): 56 data bytes
64 bytes from 10.197.100.201: icmp_seq=0 ttl=62 time=45.967 ms
64 bytes from 10.197.100.201: icmp_seq=1 ttl=62 time=44.186 ms`
但是,如果我尝试从 Pod 执行相同操作,我将无法连接。
root@one-shot-pod:/# traceroute 10.197.100.201
traceroute to 10.197.100.201 (10.197.100.201), 30 hops max, 60 byte
packets
1 10.0.0.1 (10.0.0.1) 0.046 ms 0.009 ms 0.007 ms
2 * * *
3 * * *```
我错过了什么?
解决方案
经过一番调查,我找到了问题的根本原因。基本上,通信无法正常工作,因为有一种称为 ip masquerade ( https://cloud.google.com/kubernetes-engine/docs/how-to/ip-masquerade-agent ) 的东西用于 NAT 转换。
由于 GKE 有一些默认地址被配置为不伪装(在我使用的版本上,默认值为10.0.0.0/8
:172.16.0.0/12
和192.168.0.0/16
在集群之外,解决方案是修改nonMasqueradeCIDRs
并删除10.0.0.0/8
和使用10.44.0.0/14
(GKE 集群 CIDR)。
为了做到这一点,我使用了以下配置图:
apiVersion: v1
data:
config: |-
nonMasqueradeCIDRs:
- 10.44.0.0/14
- 172.16.0.0/12
- 192.168.0.0/16
resyncInterval: 60s
kind: ConfigMap
metadata:
name: ip-masq-agent
namespace: kube-system
之后,要应用配置,您可以使用以下命令上传 configmap:
kubectl create configmap ip-masq-agent --from-file <configmap file> --namespace kube-system
推荐阅读
- javascript - 程序不在 JavaScript 中枚举
- javascript - 从特定列中删除排序
- arrays - 解析 JSON 数组的第一个元素(从谷歌表格获取数据)
- angular - Angular 显示默认页面。怎么修?
- reactjs - 如何使用 reactjs 将值存储在组件外部的一个变量中
- php - 尝试在 localhost php 中发送电子邮件时出错
- python - CVXPY 是否支持 trace(XT@A@X),其中 X、A 都是矩阵?
- javascript - 如何解决javascript中的异步等待问题?
- javascript - 从 promise 导出变量然后阻塞
- node.js - 谷歌语音到文本无法在 nodejs 上运行