简体   繁体   中英

Connection Refuse communicating from pod to service

I'm trying to communicate a service from other Pod, but i'm unable to access on it.

Im using GKE, I tried different ports and setups and looking into the code: https://github.com/spreaker/prometheus-pgbouncer-exporter

My deployment file, has:

spec:
    containers:
        - name: exporter
          image: ...
          ports:
          - containerPort: 9127
          env:
             ...

And the service:

type: NodePort
  ports:
    - port: 9127
      protocol: "TCP"
      name: exporter

When I try to describe the 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>

And the Pod itself:

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

If I access to the container, I'm receiving correctly data from 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 ....

Also doing a port-forward to the service it works:

$ 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

Now im getting this error from other pod in the same network:

curl 10.36.7.40:9127/metrics
curl: (7) Failed to connect to 10.36.7.40 port 9127: Connection refused

Also If I create a LivenessProbe TCP to the 9127, im getting this error:

Liveness probe failed: dial tcp 10.36.7.40:9127: connect: connection refused

I don't see what im doing wrong, im using the same setup for other services.

Thanks in advance!

So the problem was:

Instead to use 127.0.0.1 for the PGBOUNCER_EXPORTER_HOST i have to use 0.0.0.0 .

Thats solves the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM