为什么 Pod 无法连接到其他网络?(在新版本的 Kubernetes 中)

为什么 Pod 无法连接到其他网络?(在新版本的 Kubernetes 中)

我在 GCP 中有两个项目:

  1. 使用 Kubernetes Nodes v1.8.8-gke.0。以及 Kubernetes 之外但在默认网络中的数据库。所有 Pod 都可以连接到此服务器和所有端口
  2. 使用 Kubernetes Nodes v1.9.7-gke.3 和 Kubernetes 之外但在默认网络中的数据库。没有 pod 可以连接到此服务器。Traceroute 测试失败。

为何此 Pod 无法连接?有什么想法吗?

谢谢。

答案1

我在这里向谷歌报告了这个问题:https://issuetracker.google.com/issues/111986281

他们说这是 Kubernetes 1.9 中的一个问题:

Beginning with Kubernetes version 1.9.x, automatic firewall rules have changed such that workloads in your Kubernetes Engine cluster cannot communicate with other Compute Engine VMs that are on the same network, but outside the cluster. This change was made for security reasons.

下一个链接是解决方案:https://cloud.google.com/kubernetes-engine/docs/troubleshooting#autofirewall

基本上:

首先,找到你的集群的网络: gcloud container clusters describe [CLUSTER_NAME] --format=get"(network)"

然后获取用于容器的集群的 IPv4 CIDR:

gcloud container clusters describe [CLUSTER_NAME] --format=get"(clusterIpv4Cidr)"

最后为网络创建防火墙规则,以 CIDR 作为源范围,并允许所有协议:

gcloud compute firewall-rules create "[CLUSTER_NAME]-to-all-vms-on-network" --network="[NETWORK]" --source-ranges="[CLUSTER_IPV4_CIDR]" --allow=tcp,udp,icmp,esp,ah,sctp

答案2

由于您在 GCP 中有两个不同的数据库服务器,因此它们可能具有不同的配置。您使用的是 Cloud SQL 还是安装在 GCE VM 上的数据库服务器?对于 Cloud SLQ,请确保您的集群节点的外部 IP 地址在 Cloud SQL 实例的授权网络上列入白名单。如果在 GCE VM 上运行数据库,我建议检查防火墙规则以确保它们允许通过正确的端口和协议传入到服务器的连接。您还可以验证数据库进程的绑定地址,以查看它是否接受来自外部 IP 地址的传入连接。(这可以通过运行“sudo netstat -plnt”来查看进程及其绑定地址来完成)。此链接可能会有帮助。

相关内容