【问题标题】:Unable to ping one service to another service in Kubernetes cluster?无法 ping 一个服务到 Kubernetes 集群中的另一个服务?
【发布时间】:2018-11-23 16:45:42
【问题描述】:

我创建了一个本地 ubuntu Kubernetes 集群,有 1 个主节点和 2 个从节点。

我在 2 个 pod 中部署了 2 个应用程序,并为这两个 pod 创建了服务,它工作正常。 我通过输入这个命令进入了 Pod 内部,

$ kubectl exec -it firstpod /bin/bash
# apt-get update

无法进行更新,出现错误:

Err http://security.debian.org jessie/updates InRelease

Err http://deb.debian.org jessie InRelease

Err http://deb.debian.org jessie-updates InRelease

Err http://security.debian.org jessie/updates Release.gpg   Temporary failure resolving 'security.debian.org' Err http://deb.debian.org jessie-backports InRelease

Err http://deb.debian.org jessie Release.gpg   Temporary failure resolving 'deb.debian.org' Err http://deb.debian.org jessie-updates Release.gpg   Temporary failure resolving 'deb.debian.org' Err http://deb.debian.org jessie-backports Release.gpg   Temporary failure resolving 'deb.debian.org' Reading package lists... Done W: Failed to fetch http://deb.debian.org/debian/dists/jessie/InRelease

W: Failed to fetch http://deb.debian.org/debian/dists/jessie-updates/InRelease

W: Failed to fetch http://security.debian.org/dists/jessie/updates/InRelease

W: Failed to fetch http://deb.debian.org/debian/dists/jessie-backports/InRelease

W: Failed to fetch http://security.debian.org/dists/jessie/updates/Release.gpg  Temporary failure resolving 'security.debian.org'

W: Failed to fetch http://deb.debian.org/debian/dists/jessie/Release.gpg  Temporary failure resolving 'deb.debian.org'

W: Failed to fetch http://deb.debian.org/debian/dists/jessie-updates/Release.gpg  Temporary failure resolving 'deb.debian.org'

W: Failed to fetch http://deb.debian.org/debian/dists/jessie-backports/Release.gpg  Temporary failure resolving 'deb.debian.org'

W: Some index files failed to download. They have been ignored, or old ones used instead.

我正在尝试 ping 我的第二个 pod 服务:

# ping secondservice (This is the service name of secondpod)
PING secondservice.default.svc.cluster.local (10.100.190.196): 56 data bytes
unable to ping.

如何从第一个节点 ping/调用第二个服务?

【问题讨论】:

  • 您是否在集群中安装了 pod 网络(calico/flannel.. 等)?您也可以查看kube-proxy pod 的日志吗?
  • 看起来你没有任何网络...
  • 是的,我已经安装了 flannel 网络,所有系统 pod 都工作正常。这是日志

标签: kubernetes kubernetes-service


【解决方案1】:

我在那里看到了两个(不相关的)问题。我将专注于第二个,因为我不清楚第一个(有什么问题?)。

所以,您想知道为什么以下方法不起作用:

# ping secondservice 

这不是一个错误或意外(实际上,我写过它here)。简而言之:FQDN secondservice.default.svc.cluster.local 通过 DNS 插件解析为一个虚拟 IP (VIP),这个 VIP 的本质是它是虚拟的,也就是说,它没有连接到网络接口,它只是一个一堆 iptables 规则。因此,基于 ICMP 的 ping 没有什么可对付的,因为它不是“真正的”IP。不过,您可以curl 服务。假设服务在端口 9876 上运行,以下应该可以工作:

# curl secondservice:9876

【讨论】:

  • 嗨迈克尔,第一和第二有 2 个 pod,分别服务 firstservice 和 secondservice。现在我在 firstpod 中输入命令:kubectl exec -it firstpod /bin/bash。从这里我输入你的curl 命令 curl secondservice:3011 。但是输出什么也没显示。这是正确的还是有其他方法。
  • 由于我不知道您的应用程序,我不知道预期的输出是什么。 “什么都不显示”是什么意思?请执行curl -v 并使用输出更新您的问题。
  • 嗨,我知道默认情况下我们无法 Ping k8s 服务,但无论如何我可以配置该服务,以便将该 ICMP 请求转发到物理 pod?我知道我可以使用 curl 来测试连接性,但在我的用例中,同时拥有 TCP 和 ICMP 消息将是有益的。你知道这是否可能吗?
猜你喜欢
  • 1970-01-01
  • 2020-03-18
  • 1970-01-01
  • 2021-06-10
  • 1970-01-01
  • 2019-02-08
  • 2015-10-18
  • 2018-11-08
  • 2020-11-27
相关资源
最近更新 更多