kubernetes - Connection 拒绝从 pod 到服务的通信
问题描述
我正在尝试与其他 Pod 通信服务,但我无法访问它。
我使用 GKE,我尝试了不同的端口和设置并查看了代码:https ://github.com/spreaker/prometheus-pgbouncer-exporter
我的部署文件有:
spec:
containers:
- name: exporter
image: ...
ports:
- containerPort: 9127
env:
...
和服务:
type: NodePort
ports:
- port: 9127
protocol: "TCP"
name: exporter
当我尝试描述 svc 时:
Name: ...-pg-bouncer-exporter-service
Namespace: backend
Labels: app=...-pg-bouncer-exporter
Annotations: <none>
Selector: app=...-pg-bouncer-exporter
Type: NodePort
IP: 10.0.19.80
Port: exporter 9127/TCP
TargetPort: 9127/TCP
NodePort: exporter 31296/TCP
Endpoints: 10.36.7.40:9127
Session Affinity: None
External Traffic Policy: Cluster
Events: <none>
Pod 本身:
Containers:
exporter:
Container ID: docker://...
Image: ...
Image ID: docker-pullable:...
Port: 9127/TCP
Host Port: 0/TCP
State: Running
Started: Wed, 10 Jul 2019 11:17:38 +0200
Ready: True
Restart Count: 0
如果我访问容器,我将从 curl 正确接收数据:
/ # curl localhost:9127/metrics
# HELP process_virtual_memory_bytes Virtual memory size in bytes.
# TYPE process_virtual_memory_bytes gauge
process_virtual_memory_bytes ....
还对其工作的服务进行端口转发:
$ kubectl port-forward services/...-pg-bouncer-exporter-service 9127:9127 -n backend
Forwarding from 127.0.0.1:9127 -> 9127
Forwarding from [::1]:9127 -> 9127
Handling connection for 9127
现在我从同一网络中的其他 pod 收到此错误:
curl 10.36.7.40:9127/metrics
curl: (7) Failed to connect to 10.36.7.40 port 9127: Connection refused
此外,如果我为 9127 创建 LivenessProbe TCP,我会收到此错误:
Liveness probe failed: dial tcp 10.36.7.40:9127: connect: connection refused
我看不出我做错了什么,我对其他服务使用相同的设置。
提前致谢!
解决方案
所以问题是:
而不是127.0.0.1
用于 PGBOUNCER_EXPORTER_HOST 我必须使用0.0.0.0
.
那就是解决问题。
推荐阅读
- sql - 子查询中的 PostGreSql ISNULL 或 Coalesce
- typescript - 如何在 TypeScript 3.0 中使用项目引用?
- html - 悬停时显示 div
- python - 计算多个熊猫列中的出现次数
- sass - node-sass 无法识别所有 @import
- node.js - 如何使用 dynode 连接到本地 dynamo db
- c# - 当我计算 28/07/2018 和 01/08/2018 之间的持续时间时,结果是两天。正确答案是四天。我的错误是什么?
- ios - 在 didupdatelocation 内运行的 Mapview 不会让用户在地图上滚动
- java - 在 Java 9 上运行应用程序时出现错误“找不到模块”:log4j.core
- sql - 无法过滤掉 NULL 包含列