NATS server is giving EAI_AGAIN error in Node.js app

10/10/2021

I'm trying to run microservices locally (single-node machine). And I'm getting this strange error:

Error: getaddrinfo EAI_AGAIN nats-service
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:71:26) {
  errno: -3001,
  code: 'EAI_AGAIN',
  syscall: 'getaddrinfo',
  hostname: 'nats-service'
}

Below is the config:

apiVersion: v1
kind: Service
metadata:
  name: nats-service
spec:
  selector:
    app: nats-server
  ports:
    - name: client
      protocol: TCP
      port: 4222
      targetPort: 4222
    - name: monitoring
      protocol: TCP
      port: 8222
      targetPort: 8222
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: nats-deployment
spec:
  selector:
    matchLabels:
      app: nats-server
  template:
    metadata:
      labels:
        app: nats-server
    spec:
      containers:
        - name: nats
          image: nats-streaming:latest
          args:
            - '-p'
            - '4222'
            - '-m'
            - '8222'
            - '-hbi'
            - '1m'
            - '-hbt'
            - '5s'
            - '-hbf'
            - '3'
            - '-SD'
            - '-cid'
            - 'msrumon'
          resources:
            requests:
              cpu: 100m
              memory: 128Mi
            limits:
              cpu: 1000m
              memory: 256Mi

My app is built on top of NestJS framework. And below is the main.ts file:

import { NestFactory } from '@nestjs/core';
import { MicroserviceOptions, Transport } from '@nestjs/microservices';
import { AppModule } from './app.module';
async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  app.connectMicroservice<MicroserviceOptions>(
    {
      transport: Transport.NATS,
      options: {
        servers: 'nats://nats-service:4222',
        queue: 'app',
      },
    },
    { inheritAppConfig: true },
  );
  await app.startAllMicroservices();
  await app.listen(3000);
}
bootstrap();

All the configs are at default namespace. Please help me on what I'm doing wrong. This is the project I'm practicing on right now.

Edit: Answering first comment:

Cluster setup was pretty much straight-forward. I just installed Docker Desktop via Chocolatey package manager and enabled Kubernetes. Below is the version outputs (as of Oct 12th 2021):

$ docker version
Client:
 Version:           19.03.12
 API version:       1.40
 Go version:        go1.13.12
 Git commit:        0ed913b8-
 Built:             07/28/2020 16:36:03
 OS/Arch:           windows/amd64
 Experimental:      false
error during connect: Get http://%2F%2F.%2Fpipe%2FdockerDesktopLinuxEngine/v1.40/version: open //./pipe/dockerDesktopLinuxEngine: The system cannot find the file specified.
$ kubectl version
Client Version: version.Info{Major:"1", Minor:"22", GitVersion:"v1.22.2", GitCommit:"8b5a19147530eaac9476b0ab82980b4088bbc1b2", GitTreeState:"clean", BuildDate:"2021-09-15T21:38:50Z", GoVersion:"go1.16.8", Compiler:"gc", Platform:"windows/amd64"}
Server Version: version.Info{Major:"1", Minor:"21", GitVersion:"v1.21.4", GitCommit:"3cce4a82b44f032d0cd1a1790e6d2f5a55d20aae", GitTreeState:"clean", BuildDate:"2021-08-11T18:10:22Z", GoVersion:"go1.16.7", Compiler:"gc", Platform:"linux/amd64"}
$ kubectl describe nodes
Name:               docker-desktop
Roles:              control-plane,master
Labels:             beta.kubernetes.io/arch=amd64
                    beta.kubernetes.io/os=linux
                    kubernetes.io/arch=amd64
                    kubernetes.io/hostname=docker-desktop
                    kubernetes.io/os=linux
                    node-role.kubernetes.io/control-plane=
                    node-role.kubernetes.io/master=
                    node.kubernetes.io/exclude-from-external-load-balancers=
Annotations:        kubeadm.alpha.kubernetes.io/cri-socket: /var/run/dockershim.sock
                    node.alpha.kubernetes.io/ttl: 0
                    volumes.kubernetes.io/controller-managed-attach-detach: true
CreationTimestamp:  Thu, 02 Sep 2021 15:48:31 +0600
Taints:             <none>
Unschedulable:      false
Lease:
  HolderIdentity:  docker-desktop
  AcquireTime:     <unset>
  RenewTime:       Tue, 12 Oct 2021 20:10:17 +0600
Conditions:
  Type             Status  LastHeartbeatTime                 LastTransitionTime                Reason                       Message
  ----             ------  -----------------                 ------------------                ------                       -------
  MemoryPressure   False   Tue, 12 Oct 2021 20:10:16 +0600   Mon, 27 Sep 2021 01:41:23 +0600   KubeletHasSufficientMemory   kubelet has sufficient memory available
  DiskPressure     False   Tue, 12 Oct 2021 20:10:16 +0600   Mon, 27 Sep 2021 01:41:23 +0600   KubeletHasNoDiskPressure     kubelet has no disk pressure
  PIDPressure      False   Tue, 12 Oct 2021 20:10:16 +0600   Mon, 27 Sep 2021 01:41:23 +0600   KubeletHasSufficientPID      kubelet has sufficient PID available
  Ready            True    Tue, 12 Oct 2021 20:10:16 +0600   Wed, 29 Sep 2021 17:57:45 +0600   KubeletReady                 kubelet is posting ready status
Addresses:
  InternalIP:  192.168.65.4
  Hostname:    docker-desktop
Capacity:
  cpu:                16
  ephemeral-storage:  263174212Ki
  hugepages-1Gi:      0
  hugepages-2Mi:      0
  memory:             13032308Ki
  pods:               110
Allocatable:
  cpu:                16
  ephemeral-storage:  242541353378
  hugepages-1Gi:      0
  hugepages-2Mi:      0
  memory:             12929908Ki
  pods:               110
System Info:
  Machine ID:                 1dd2a319-0b08-4b0a-8e40-eac07615fe06
  System UUID:                1dd2a319-0b08-4b0a-8e40-eac07615fe06
  Boot ID:                    5f9b8734-d4dd-4120-beef-cc239cbbaa66
  Kernel Version:             5.10.16.3-microsoft-standard-WSL2
  OS Image:                   Docker Desktop
  Operating System:           linux
  Architecture:               amd64
  Container Runtime Version:  docker://20.10.8
  Kubelet Version:            v1.21.4
  Kube-Proxy Version:         v1.21.4
Non-terminated Pods:          (10 in total)
  Namespace                   Name                                         CPU Requests  CPU Limits  Memory Requests  Memory Limits  Age
  ---------                   ----                                         ------------  ----------  ---------------  -------------  ---
  ingress-nginx               ingress-nginx-controller-748d8ff6c7-6fbsh    100m (0%)     0 (0%)      90Mi (0%)        0 (0%)         10d
  kube-system                 coredns-558bd4d5db-2mhks                     100m (0%)     0 (0%)      70Mi (0%)        170Mi (1%)     40d
  kube-system                 coredns-558bd4d5db-k8pfc                     100m (0%)     0 (0%)      70Mi (0%)        170Mi (1%)     40d
  kube-system                 etcd-docker-desktop                          100m (0%)     0 (0%)      100Mi (0%)       0 (0%)         40d
  kube-system                 kube-apiserver-docker-desktop                250m (1%)     0 (0%)      0 (0%)           0 (0%)         40d
  kube-system                 kube-controller-manager-docker-desktop       200m (1%)     0 (0%)      0 (0%)           0 (0%)         40d
  kube-system                 kube-proxy-k42wv                             0 (0%)        0 (0%)      0 (0%)           0 (0%)         40d
  kube-system                 kube-scheduler-docker-desktop                100m (0%)     0 (0%)      0 (0%)           0 (0%)         40d
  kube-system                 storage-provisioner                          0 (0%)        0 (0%)      0 (0%)           0 (0%)         40d
  kube-system                 vpnkit-controller                            0 (0%)        0 (0%)      0 (0%)           0 (0%)         40d
Allocated resources:
  (Total limits may be over 100 percent, i.e., overcommitted.)
  Resource           Requests    Limits
  --------           --------    ------
  cpu                950m (5%)   0 (0%)
  memory             330Mi (2%)  340Mi (2%)
  ephemeral-storage  0 (0%)      0 (0%)
  hugepages-1Gi      0 (0%)      0 (0%)
  hugepages-2Mi      0 (0%)      0 (0%)
Events:
  Type    Reason                   Age                    From        Message
  ----    ------                   ----                   ----        -------
  Normal  Starting                 3h47m                  kubelet     Starting kubelet.
  Normal  NodeAllocatableEnforced  3h47m                  kubelet     Updated Node Allocatable limit across pods
  Normal  NodeHasSufficientPID     3h47m (x7 over 3h47m)  kubelet     Node docker-desktop status is now: NodeHasSufficientPID
  Normal  NodeHasSufficientMemory  3h47m (x8 over 3h47m)  kubelet     Node docker-desktop status is now: NodeHasSufficientMemory
  Normal  NodeHasNoDiskPressure    3h47m (x8 over 3h47m)  kubelet     Node docker-desktop status is now: NodeHasNoDiskPressure
  Normal  Starting                 3h47m                  kube-proxy  Starting kube-proxy.
  Normal  Starting                 7m3s                   kubelet     Starting kubelet.
  Normal  NodeAllocatableEnforced  7m3s                   kubelet     Updated Node Allocatable limit across pods
  Normal  NodeHasSufficientMemory  6m59s (x8 over 7m3s)   kubelet     Node docker-desktop status is now: NodeHasSufficientMemory
  Normal  NodeHasNoDiskPressure    6m59s (x8 over 7m3s)   kubelet     Node docker-desktop status is now: NodeHasNoDiskPressure
  Normal  NodeHasSufficientPID     6m59s (x7 over 7m3s)   kubelet     Node docker-desktop status is now: NodeHasSufficientPID
  Normal  Starting                 6m46s                  kube-proxy  Starting kube-proxy.
-- msrumon
kubernetes
nats-streaming-server
nestjs

0 Answers