1

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
  • 1,250
  • 1
  • 10
  • 27
  • How did you set up your cluster and which version did you use? It is important to eventual reproduce your problem. When exactly did you get this error? – Mikołaj Głodziak Oct 11 '21 at 11:32
  • It's local machine, using `docker-desktop` as Kubernetes context and [Skaffold](https://skaffold.dev) to deploy the apps. If you're wondering the node description, it's [here](https://stackoverflow.com/questions/69367067/skaffold-is-not-fully-running-all-the-services#comment122691554_69367067). You can reproduce the issue by cloning the project and running `skaffold run --tail` command. – msrumon Oct 11 '21 at 11:55
  • Please do not use external services such as pastebin. Additionally, do not link to information that is included in the comment under another question. (For example, if that question is removed, we will be left without information). Edit question and add all information directly in one question. – Mikołaj Głodziak Oct 12 '21 at 12:59
  • Thanks for your advice. Let me know what information is missing from the question, I'll gladly add them. Also suggest me what should I use for pasting very long texts, 'cause SO comments doesn't accept beyond a certain amount of characters. Anyway, I've edited the post answering to your first comment. – msrumon Oct 12 '21 at 14:11
  • Cloud you clarify: you've shown us a nats-server deployment and service, which is the backend you're connecting to. But where does your NodeJS app run? Is it in Kubernetes as well, or are you testing code outside of your cluster? In the latter case, it is normal NodeJS would not be able to resolve k8s service dns names – SYN Oct 13 '21 at 23:06
  • Yes it's in the cluster too. – msrumon Oct 14 '21 at 05:29

0 Answers0