首页 > 解决方案 > 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

我看不出我做错了什么,我对其他服务使用相同的设置。

提前致谢!

标签: kubernetesportgoogle-kubernetes-engine

解决方案


所以问题是:

而不是127.0.0.1用于 PGBOUNCER_EXPORTER_HOST 我必须使用0.0.0.0.

那就是解决问题。


推荐阅读