I hope you are all doing fine I am developing a microservices application. I am using Kubernetes and skaffold. I run skaffold dev and it shows NatsError: Could not connect to server: Error: getaddrinfo EAI_AGAIN nats-srv and MongooseServerSelectionError: getaddrinfo EAI_AGAIN auth-mongo-srv for auth service. Before, the application used to work fine. I don't understand why this happens. I am attaching screenshots of it. Could you please help me solve it? I have been stuck for a few days with that problem, and I still cannot find a solution.
I checked the whole code if I had any misconfigurations but no. I also checked the example at the microservices course I am actually pursuing. For days in a row I can't solve that problem.
nats-depl.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: nats-depl
spec:
replicas: 1
selector:
matchLabels:
app: nats
template:
metadata:
labels:
app: nats
spec:
containers:
- name: nats
image: nats-streaming:0.17.0
args:
[
'-p',
'4222',
'-m',
'8222',
'-hbi',
'5s',
'-hbt',
'5s',
'-hbf',
'2',
'-SD',
'-cid',
'ticketing',
]
---
apiVersion: v1
kind: Service
metadata:
name: nats-srv
spec:
selector:
app: nats
ports:
- name: client
protocol: TCP
port: 4222
targetPort: 4222
- name: monitoring
protocol: TCP
port: 8222
targetPort: 8222
expiration-depl.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: expiration-depl
spec:
replicas: 1
selector:
matchLabels:
app: expiration
template:
metadata:
labels:
app: expiration
spec:
restartPolicy: Always
containers:
- name: expiration
image: endrieb/expiration
env:
- name: NATS_CLIENT_ID
valueFrom:
fieldRef:
fieldPath: metadata.name
- name: NATS_URL
value: 'http://nats-srv:4222'
- name: NATS_CLUSTER_ID
value: ticketing
- name: REDIS_HOST
value: expiration-redis-srv
code in expiration index.ts
import { natsWrapper } from './nats-wrapper';
import { OrderCreatedListener } from './events/listeners/order-created-listener';
const start = async () => {
console.log("Expiration starting up ...");
if (!process.env.NATS_CLIENT_ID) {
throw new Error('NATS_CLIENT_ID must be defined');
}
if (!process.env.NATS_URL) {
throw new Error('NATS_URL must be defined');
}
if (!process.env.NATS_CLUSTER_ID) {
throw new Error('NATS_CLUSTER_ID must be defined');
}
try {
await natsWrapper.connect(
process.env.NATS_CLUSTER_ID,
process.env.NATS_CLIENT_ID,
process.env.NATS_URL,
);
natsWrapper.client.on('close', () => {
console.log('NATS connection closed!');
process.exit();
});
process.on('SIGINT', () => natsWrapper.client.close());
process.on('SIGTERM', () => natsWrapper.client.close());
new OrderCreatedListener(natsWrapper.client).listen();
} catch (err) {
console.error(err);
}
};
start();