<p>I have the following microservice based node.js program: <code>posts</code> is responsible for creating a post and sending the corresponding event to the <code>event bus</code> via an axios <code>POST</code> request. The <code>event bus</code> also establishes connection to <code>posts</code> via an axios <code>GET</code> request upon startup.
The <code>GET</code> request from <code>event bus</code> to <code>posts</code> is successful, but the <code>POST</code> request from <code>posts</code> to <code>event bus</code> fails with the error <code>getaddrinfo ENOTFOUND event-bus-srv</code>. Both <code>posts</code> and <code>event bus</code> are running in pods managed by kubernetes within the same node. Only <code>posts</code> is available to the user vis the URL <code>http://localhost:31218/</code>. When I use postman to post to the endpoint <code>http://localhost:31218/posts</code>, I receive code 201 successfully, but the event is never forwarded to <code>event bus</code>.
My question is this: what is causing <code>getaddrinfo ENOTFOUND event-bus-srv</code> and how do I fix it?</p>
<p>Relavent code:</p>
<ol>
<li>posts index.js</li>
<li>event bus index.js</li>
<li>EVENT BUS KUBERNETES DEPLOYMENT FILE</li>
<li>POSTS KUBERNETES DEPLOYMENT FILE</li>
<li>POSTS KUBERNETES NODEPORT FILE</li>
</ol>
<pre><code>_____________________________________POSTS___________________________________________
const express = require('express');
const { randomBytes } = require('crypto');
const bodyParser = require('body-parser');
const cors = require('cors');
const axios = require('axios');

const app = express();
app.use(cors());
app.use(bodyParser.json());


const posts = {};


app.get('/posts', (req, res) =&gt; {
  res.send(posts);
});

app.post('/posts', async(req, res) =&gt; {
  const id = randomBytes(4).toString('hex');
  const { title } = req.body;
  posts[id] = {
    id, title
  };

  await axios.post('http://event-bus-srv:4005/events', {
      type: 'PostCreated',
      data: {
        id, title
      }
  }).catch((err) =&gt; {
    console.log(&quot;сбой такой: &quot; + err.message);
  });

  res.status(201).send(posts[id]);
});

app.post('/events', (req, res) =&gt; {
  res.status(200);
})

app.listen(4000, () =&gt; {
  console.log('Listening to port ' + 4000);
});

_____________________________________EVENT BUS___________________________________________
const express = require('express');
const bodyParser = require('body-parser');
const axios = require('axios');

const app = express();
app.use(bodyParser.json());

const events = [];

app.get('/events', (req, res) =&gt; {
    res.send(events);
});

app.post('/events', (req, res) =&gt; {
    const event = req.body;

    events.push(event);

    axios.post('http://posts-clusterip-svr:4000/events', event).catch((err) =&gt; {
        console.log(err.message);
      });

    res.send({status: 'OK'});
});

app.listen(4005, async() =&gt; {
    console.log(&quot;listening to &quot; + 4005);
    const res = await axios.get('http://posts-clusterip-svr:4000/posts').catch((err) =&gt; {
      console.log(&quot;сбой такой: &quot; + err.message);
    });
});

___________EVENT BUS KUBERNETES DEPLOYMENT/SERVICE FILE_________________________________

apiVersion: apps/v1
kind: Deployment
metadata: 
  name: event-bus-depl
spec:
  replicas: 1
  selector:
    matchLabels:
      app: event-bus
  template:
    metadata:
      labels:
        app: event-bus
    spec:
      containers:
        - name: event-bus
          image: wliamwhite/event-bus:latest
---
apiVersion: v1
kind: Service
metadata:
  name: event-bus-svr
spec:
  selector:
    app: event-bus
  type: ClusterIP
  ports:
    - name: event-bus
      protocol: TCP
      port: 4005
      targetPort: 4005

___________POSTS KUBERNETES DEPLOYMENT/SERVICE FILE_____________________________________
apiVersion: apps/v1
kind: Deployment
metadata: 
  name: posts-depl
spec:
  replicas: 1
  selector:
    matchLabels:
      app: posts
  template:
    metadata:
      labels:
        app: posts
    spec:
      containers:
        - name: posts
          image: wliamwhite/posts:latest
---
apiVersion: v1
kind: Service
metadata:
  name: posts-clusterip-svr
spec:
  type: ClusterIP
  selector:
    app: posts
  ports:
    - name: posts
      protocol: TCP
      port: 4000
      targetPort: 4000

___________POSTS KUBERNETES NODEPORT FILE_________________________________________
apiVersion: v1
kind: Service
metadata:
  name: posts-svr
spec:
  type: NodePort
  selector:
    app: posts
  ports:
    - name: posts
      protocol: TCP
      port: 4000
      targetPort: 4000
</code></pre>

Liam White
<p>Aside from the event-bus-srv and event-bus-svr name confusion. The error message you are having typically indicates that the DNS resolution failed from the hostname.</p>
<p>Things to consider for this concern:</p>
<ol>
<li>Just like what @DavidMaze mentioned you need to double check the hostname and make sure it is properly spelled.</li>
<li>Double check also the configuration files or code where the hostname is used.</li>
<li>Make sure that DNS servers are correctly configured. You can do a ping or nslookup command for testing.</li>
<li>Make sure hostname is properly configured in DNS record and point to the right IP address</li>
<li>Check firewall Rules that might be blocking the connection from hostname and ensure necessary ports are open.</li>
</ol>
