Search code examples
kubernetesnestjsmicroservicesbackend

What should be the host name in nestjs hybrid microservice when deployed on Kubernetes


Tech stack - nestjs - 2 microservice kubernetes - AWS EKS Ingress - nginx

Hybrid

  const app = await NestFactory.create(AppModule);
  const microservice = app.connectMicroservice<MicroserviceOptions>(
    {
      transport: Transport.TCP,
      options: {
        host: process.env.TCP_HOST,
        port: parseInt(process.env.TCP_EVALUATION_PORT),
      },
    },
    { inheritAppConfig: true },
  );
  await app.startAllMicroservices();
  await app.listen(parseInt(config.get(ConfigEnum.PORT)), '0.0.0.0');

env

  TCP_HOST: '0.0.0.0'
  TCP_CORE_PORT: 8080
  TCP_EVALUATION_PORT: 8080

Error

"connect ECONNREFUSED 0.0.0.0:8080"

Do I need to expose this port in docker or add it somewhere in the security group? Or may be need to pass a different host?

Note: App is deployed properly without any error and HTTP Rest API seems to be working fine but not the TCP @messagePattern!

Thanks


Solution

  • Create a service to match the instances you want to connect to and use the service name.