<p>I have the following problem I have an api in nestjs and micro service that the gateway api accesses services with TCP runs normally but when I create the pods in kubernetes it gives the following error:</p>
<p><strong>[Server] Error: listen EADDRNOTAVAIL: address not available 1
92.168.x.x:8879</strong></p>
<p>app.module.ts from api-gateway:</p>
<pre><code>import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { ClientsModule, Transport } from '@nestjs/microservices';
import { AppService } from './app.service';

@Module({
  imports: [
    ClientsModule.register([
      {
        name: 'SERVICE_A',
        transport: Transport.TCP,
        options: {
          host: '192.168.x.x',
          port: 8888,
        },
      },
      {
        name: 'SERVICE_B',
        transport: Transport.TCP,
        options: {
          host: '192.168.x.x',
          port: 8889,
        },
      },
      {
        name: 'USER',
        transport: Transport.TCP,
        options: {
          host: '192.168.x.x',
          port: 8887,
        },
      },
      {
        name: 'USER_LOGIN',
        transport: Transport.TCP,
        options: {
          host: '192.168.x.x',
          port: 8886,
        },
      },
      {
        name: 'USER_CREATE',
        transport: Transport.TCP,
        options: {
          host: '192.168.x.x',
          port: 8885,
        },
      },
      {
        name: 'USER_UPDATE',
        transport: Transport.TCP,
        options: {
          host: '192.168.x.x',
          port: 8884,
        },
      },
      {
        name: 'CATEGORY',
        transport: Transport.TCP,
        options: {
          host: '192.168.x.x',
          port: 8883,
        },
      },
      {
        name: 'CATEGORY_BUSCA',
        transport: Transport.TCP,
        options: {
          host: '192.168.x.x',
          port: 8882,
        },
      },
      {
        name: 'CATEGORY_PRODUCT',
        transport: Transport.TCP,
        options: {
          host: '192.168.x.x',
          port: 8881,
        },
      },
      {
        name: 'USER_SENHA',
        transport: Transport.TCP,
        options: {
          host: '192.168.x.x',
          port: 8880,
        },
      },
      {
        name: 'ADM_CONTACT',
        transport: Transport.TCP,
        options: {
          host: '192.168.x.x',
          port: 8879,
        },
      },
      {
        name: 'LOCATION',
        transport: Transport.TCP,
        options: {
          host: '192.168.x.x',
          port: 8878,
        },
      },
      {
        name: 'PRODUCT_STAR',
        transport: Transport.TCP,
        options: {
          host: '192.168.x.x',
          port: 8877,
        },
      },
      {
        name: 'PRODUCT_SINGLE',
        transport: Transport.TCP,
        options: {
          host: '192.168.x.x',
          port: 8876,
        },
      },
      {
        name: 'PRODUCT_GET_STAR',
        transport: Transport.TCP,
        options: {
          host: '192.168.x.x',
          port: 8875,
        },
      },
      {
        name: 'PURCHASE_CREATE',
        transport: Transport.TCP,
        options: {
          host: '192.168.x.x',
          port: 8874,
        },
      },
      {
        name: 'PURCHASE_GET_CART',
        transport: Transport.TCP,
        options: {
          host: '192.168.x.x',
          port: 8873,
        },
      },
      {
        name: 'PURCHASE_GET',
        transport: Transport.TCP,
        options: {
          host: '192.168.x.x',
          port: 8870,
        },
      }
    ]),
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}
</code></pre>
<p>my main.ts of my service:</p>
<pre><code>import { NestFactory } from '@nestjs/core';
import { Transport } from '@nestjs/microservices';
import { AppModule } from './app.module';
import { Logger } from '@nestjs/common';

const logger = new Logger();

async function bootstrap() {
  const app = await NestFactory.createMicroservice(AppModule, {
    transport: Transport.TCP,
    options: {
      host: '192.168.x.x',
      port: 8879,
    },
  });
  app.listen(() =&gt; logger.log('Microservice ADM CONTACT is listening'));
}
bootstrap();
</code></pre>
<p>When I run the service it presents in kubernetes with <strong>kubectl logs</strong> it gives this error:</p>
<pre><code>[Nest] 1   - 05/19/2022, 10:12:59 PM   [NestFactory] Starting Nest application...
[Nest] 1   - 05/19/2022, 10:13:00 PM   [InstanceLoader] TypeOrmModule dependencies initialized
 +281ms
[Nest] 1   - 05/19/2022, 10:13:00 PM   [InstanceLoader] AppModule dependencies initialized
 +0ms
[Nest] 1   - 05/19/2022, 10:13:00 PM   [InstanceLoader] TypeOrmCoreModule dependencies initialized
 +191ms
[Nest] 1   - 05/19/2022, 10:13:00 PM   [NestMicroservice] Nest microservice successfully started
 +9ms
[Nest] 1   - 05/19/2022, 10:13:00 PM   [Server] Error: listen EADDRNOTAVAIL: address not available 1
92.168.x.x:8879 +6ms
</code></pre>
<p>If you need I edit the question and add my <strong>yamls</strong></p>
<p>Does anyone have any idea of this conflict?</p>
<p><strong><a href="https://stackoverflow.com/questions/72890570/im-trying-to-convert-my-application-to-kubenetes-and-nginx-ingress-controller/72891420#72891420">[solved]</a></strong></p>

Rafael Souza
<p>Your code needs updating to be Kubernetes-aware. When your container image is scheduled to a Pod, the Pod will be assigned an IP by the kubelet.</p>
<p>As @mdaniel has mentioned, your code needs to bind to 0.0.0.0. Your k8s deployment yaml will need to establish services for your endpoints, and your code should use the name of these services: your deployment yaml will set the service name, so this <strong>will</strong> be known ahead of time.</p>
<p>Coming from the linked thread [https://stackoverflow.com/questions/72399521/access-pod-from-another-pod-with-kubernetes-url/72408970#72408970] you will be able to access from the browser either a) when you run the <code>kubectl port-forward svc/servicename</code> commands, or b) if this is being deployed in production for other users, your k8s cluster will have an Ingress and a method for routing to your k8s service.</p>
<p>Explaining how to setup Ingress to somebody who isn't a k8s admin is beyond the scope of a S/O answer I'm afraid though, due to the variables of your environment and complexity.</p>
