0

I have deployed consul using hashicorp-consul-helm-chart now, I want to connect to the consul from my Node.js project.

Therefore, I created an object like this : (using 'consul' npm package)

import consul from 'consul';

var consulObj = new consul({
  host: 'xxx.xxx.xxx.xxx',
  promisify: true
});

var watch = consulObj.watch({
  method: consulObj.kv.get,
  options: { key: 'config' },
  backoffFactor: 1000,
});

I have got the host value from kubectl get endpoints used the value opposite to consul-server

enter image description here

still, i get consul: kv.get: connect ETIMEDOUT when I run the code. what could be the reason? Thanks in advance!

Keval Bhogayata
  • 4,422
  • 3
  • 13
  • 36
  • stupid question: can you confirm your pods are running? I also assume you mean `kubectl get endpoints` – Jordan Shaw Jan 28 '21 at 04:08
  • i would sugegst you to check the connection using consul agent first. try to connect with side container first docker image : consul:1.2.0 however as Jordan mentioned your PODs are up & running ? – Harsh Manvar Jan 28 '21 at 04:29
  • Also, what are you using as HOST internal SVC IP or SVC name, if using internal SVC name both are in same namespace? Are you running your Node program locally or running on same cluster ? – Harsh Manvar Jan 28 '21 at 04:31
  • Yes I meant kubectl get endpoints, thats just a typo, corrected now @JordanShaw – Keval Bhogayata Jan 28 '21 at 04:44
  • Yes, consul pods are up and running, moreover code runs on the same cluster. The namespace is different ! @HarshManvar – Keval Bhogayata Jan 28 '21 at 04:46
  • @KevalBhogayata are you using internal IP or SVC name in host ? – Harsh Manvar Jan 28 '21 at 04:46
  • not using service name, using the IP that I am getting in kubectl get endpoints, not sure if its called Internal IP – Keval Bhogayata Jan 28 '21 at 04:48
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/227935/discussion-between-harsh-manvar-and-keval-bhogayata). – Harsh Manvar Jan 28 '21 at 04:49

1 Answers1

0

You should be accessing the Consul client which is running on the node where your app is located instead of directly accessing the server.

Details can be found in the accepted answer for Hashicorp Consul, Agent/Client access.

Blake Covarrubias
  • 2,138
  • 2
  • 6
  • 14