Kubernetes returns 中的 Prometheus 运行 来自服务器的空回复和权限被拒绝

Prometheus running in Kubernetes returns Empty reply from server and permission denied

我对 Kubernetes 和 Prometheus 还很陌生。我一直在跟着 these directions 一步步走。

我进入了我进行端口转发的部分:

kubectl port-forward <prometheus pod> 8080:9090 -n monitoring

此时我应该可以访问 http://localhost:8080 获取 Prometheus 仪表板。相反,我得到:

# curl http://localhost:8080
curl: (52) Empty reply from server

并且在端口转发过程中我的权限被拒绝:

Handling connection for 8080
E0723 19:45:40.532119   18108 portforward.go:400] an error occurred forwarding 8080 -> 9090: error forwarding port 9090 to pod 3a04bc19fcc2f23f2c1b095df8ba472b455f91d6453a72575078b858df8d87a1, uid : exit status 1: 2021/07/23 19:45:40 socat[22259] E connect(5, AF=2 127.0.0.1:9090, 16): Permission denied

如果我查看 prometheus pod 日志,它看起来很高兴:

level=info ts=2021-07-23T19:14:38.691Z caller=kubernetes.go:282 component="discovery manager scrape" discovery=kubernetes msg="Using pod service account via in-cluster config"
level=info ts=2021-07-23T19:14:38.692Z caller=kubernetes.go:282 component="discovery manager scrape" discovery=kubernetes msg="Using pod service account via in-cluster config"
level=info ts=2021-07-23T19:14:38.693Z caller=kubernetes.go:282 component="discovery manager scrape" discovery=kubernetes msg="Using pod service account via in-cluster config"
level=info ts=2021-07-23T19:14:38.695Z caller=main.go:1012 msg="Completed loading of configuration file" filename=/etc/prometheus/prometheus.yml totalDuration=10.027206ms remote_storage=8.294µs web_handler=307ns query_engine=2.796µs scrape=801.585µs scrape_sd=3.181796ms notify=23.042µs notify_sd=10.213µs rules=550.517µs
level=info ts=2021-07-23T19:14:38.695Z caller=main.go:796 msg="Server is ready to receive web requests."

我首先尝试 google,但没有找到包含以上所有内容的任何匹配项。

我不确定它是否重要运行在本地主机上,但我确实在该端口上打开了防火墙

# iptables -xvn -L|grep 8080
      21     1166 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:8080

我怀疑这个问题可能与根用户有关 运行使用 Prometheus pod。如果我 kubectl exec 进入普罗米修斯 pod,所有内容都是拥有的,并且 运行 也作为 root 用户。我看过 Prometheus 的手动安装,这些说明总是让您创建一个 Prometheus 用户和组,并 运行 作为 Prometheus 用户。但是 Prometheus 容器直接来自 dockerhub,所以我不知道如何更改 docker 图像中的用户。但这只是目前的猜测,真的不知道。

如有任何帮助,我们将不胜感激。

这是 Centos 7 服务器 运行ning Kubernetes 1.18。 Prometheus 是最新的 docker 中心映像 prom/prometheus

TIA

-乔恩

问题已通过将 centos 切换到 permissive mode 来解决。

在启用 SELinux 的系统上安装 kubernetes 期间,您应该禁用它,以便所有容器都可以访问主机文件系统。

请注意,通过 setenforce 0 禁用 SELinux 只是一个临时解决方案(就像通过 swapoff -a

关闭交换一样)

要完全禁用它们:

  • SELinux:编辑 /etc/selinux/config 并设置 SELINUX=disabled
  • 交换:编辑 /etc/fstab 并评论 (#) 交换条目