'Using Axios to communicate between pods in a Kubernetes cluster

I'm trying to get pods in a cluster to communicate using a REST API. Our services are Node.js-based. We formerly used the request networking package, but since it is now deprecated, we are migrating to the Axios network package.

The error I'm currently getting is:

tunneling socket could not be established, cause=connect ECONNREFUSED 127.0.0.1:443

When we were using the request package, we would send a network request with the following command:

request({
  'url': 'https://other-service:8000/api/endpoint',
  'json': true,
  'method', 'post',
  'body': data,
  'auth': {
    'username': '<username>',
    'password': '<password>',
    sendImmediately: true
  },
  'cert': certificate,
  'key': privateKey,
  'strictSSL': false,
  'headers': {
    'username': '<username>'
  }
});

Now, with Axios, the command we issue is:

axios({
  url: 'https://other-service:8000/api/endpoint',
  method: 'post',
  responseType: 'json',
  headers: {
    'username': '<username>'
  },
  auth: {
    'username': '<username>',
    'password': '<password>',
  },
  data: data,
  httpsAgent = tunnel.httpsOverHttps({
    key: privateKey,
    cert: certificate
  }
});

We are now getting the tunneling error:

tunneling socket could not be established, cause=connect ECONNREFUSED 127.0.0.1:443

I'm guessing the issue is related to where the tunnel package is attempting to validate the certificate, because if I comment out the line containing httpsAgent, I then get an error saying the certificate has expired.

Any help would be greatly appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source