「Kubernetes」- 无法通过 Service 访问 Pod 自身

  CREATED BY JENKINSBOT

问题描述

我们运行 Pod-A 实例,然后定义 Service-A 暴露 Pod-A 服务,然后在 Pod-A 内通过 Service-A 来访问自身,简单说就是:在 Pod 中,通过 Service 访问自己。

但是,这样网络是不通的,即 Pod-A 无法通过 Service 访问自己。然而,其他容器通过 Service-A 能够成功访问 Pod-A 服务。

原因分析

我们提交工单,得到答复如下:鉴于 kube-proxy 为 IPVS 模式,由于 LVS 的特性。如果 Pod 访问的 Service 负载到 Pod 自己,那么就会导致无法正常访问。

在我们开发集群(自建)中,kube-proxy 为 iptables 模式,所以不存在这个问题。

解决方案

遇到该问题的集群为阿里云集群,我们没有解决该问题,毕竟 Pod 通过 Service 访问自己并不是常见需求。

我们没有因为这种特殊需求而修改集群配置,毕竟能否调整是一方面,是否会产生其他附带影响是另一方面。

相关问题

docker – kubernetes pod can’t connect (through service) to self, only to other pod-containers – Stack Overflow
A pod can’t direct traffic to itself via a service · Issue #20475 · kubernetes/kubernetes · GitHub
Pod unable to connect to itself via service · Issue #61593 · kubernetes/kubernetes · GitHub
Edge case: A Pod fails to reach itself via the Service IP