1

I created a NATS Streaming Server on my Kubernetes cluster.

And "Kubectl get services" output like that:

NAME                 TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)             AGE
api-gateway-srv      NodePort    10.106.100.181   <none>        8080:30440/TCP      16m
auth-mongo-srv       ClusterIP   10.101.9.123     <none>        27017/TCP           16m
auth-srv             ClusterIP   10.102.227.91    <none>        3000/TCP            16m
radio-srv            ClusterIP   10.111.20.153    <none>        3003/TCP            16m
kubernetes           ClusterIP   10.96.0.1        <none>        443/TCP             3d13h
tv-srv               ClusterIP   10.111.88.212    <none>        3001/TCP            16m
nats-srv             ClusterIP   10.105.230.126   <none>        4222/TCP,8222/TCP   16m

On on my nats-publisher.js file like that:

const nats = require('node-nats-streaming');

const stan = nats.connect('natsserver', 'nats-cli1', {
    url: 'nats://nats-srv:4222'
});
stan.on('connect', () => {
    console.log('Links publisher connected to NATS')
}, (err, guid) => {
    if(err) console.log(err)
    else console.log(guid)
})  

And I get :

NatsError: Could not connect to server: Error: connect ECONNREFUSED 10.105.230.126:4222

But on the another service I used same connection codes for nats connection. And this service can connect successfully nats server.

Why I getting this error? Same code run as correctly on the another service but this code How can crash from this service?

akasaa
  • 1,282
  • 4
  • 13
  • 33
  • With that level of detail, you are going to be hard pressed to get good help. That said, experience shows that specific error is often caused by the Service pointing at one port and the container either listening on 127.0.0.1 or listening on a different port entirely. If you genuinely want help, you'll need to [edit your question](https://stackoverflow.com/posts/66314556/edit) with more details about the kubernetes objects and any troubleshooting steps you have already taken. – mdaniel Feb 22 '21 at 16:20
  • You should share your ingress-Nginx config. – Yilmaz Mar 26 '21 at 23:24
  • I'm actually working through the same course, and I'm getting the same error. I've posted a question on the platform, but I'd like to know if the author if this question ever figured out a solution. – binarygiant Jun 07 '21 at 19:02

1 Answers1

0

When you use command kubectl port-forward [pod_name] 4222:4222

You can see next lines at the terminal:

Forwarding from 127.0.0.1:4222 -> 4222
Forwarding from [::1]:4222 -> 4222

Use 127.0.0.1:4222 in config

anrei
  • 1
  • 1