Answers: <p>Normally, you access services using the name provided by a <code>Service</code> resource.</p>
  <p>For example, if I have a <code>Pod</code> running Redis, like this:</p>
  <pre><code>apiVersion: v1
  kind: Pod
  metadata:
    labels:
      app: redis
    name: redis
  spec:
    containers:
      - image: docker.io/redis:latest
        name: redis
        ports:
        - containerPort: 6379
          name: redis
  </code></pre>
  <p>I might have a service definition that looks like:</p>
  <pre><code>apiVersion: v1
  kind: Service
  metadata:
    name: redis
  spec:
    selector:
      app: redis
    ports:
    - port: 6379
      targetPort: redis
  </code></pre>
  <p>With these in place, from another <code>Pod</code> I can refer to the Redis
  service using the hostname <code>redis</code>:</p>
  <pre><code>[root@client /]# redis-cli -h redis
  redis:6379&gt;
  </code></pre>
  <hr />
  <p>The name and port to which we connect is controlled by the <code>Service</code>
  object. If instead of the above example I had:</p>
  <pre><code>apiVersion: v1
  kind: Service
  metadata:
    name: bob
  spec:
    selector:
      app: redis
    ports:
    - port: 2000
      targetPort: redis
  </code></pre>
  <p>I would need to connect like this:</p>
  <pre><code>[root@client /]# redis-cli -h bob -p 2000
  bob:2000&gt;
  </code></pre>
  <hr />
  <p>For more information:</p>
  <ul>
  <li><a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="nofollow noreferrer">Service</a></li>
  </ul>
  
Answers: CC BY-SA 4.0
Answers: 2022-04-28T13:02:19.707Z
Answers: 2022-04-28T13:02:19.707Z
Answers: larsks
Body: <p>So I have a few services running using nodejs, in more than one kubernetes pod.</p>
  <p>These services obviously need to talk to each other, and be able to find the database included in this kubernetes cluster.</p>
  <p>In docker-compose I could just use the container name and it would automatically route me to the correct one, with kubernetes it does not seem to be the case.</p>
  <p>How do I route to specific containers in different pods in Kubernetes? I tried service names, using the namespace set up by the pipeline's admin team (<code>&lt;POD&gt;</code>.<code>&lt;NAMESPACE&gt;</code>.svc.cluster.local), and an ExternalName, but every time I get the same error: <code>Error: getaddrinfo ENOTFOUND</code></p>
  <p>Any advice would be appreciated as I am new to kubernetes.</p>
  
Tags: <kubernetes><networking>
Title: Kubernetes container networking between pods
UserDisplayName: Flotolk
ThreadText: # Kubernetes container networking between pods
  
  (Asked by: username_0 on 2022-04-21)
  
  So I have a few services running using nodejs, in more than one kubernetes pod.
  
  These services obviously need to talk to each other, and be able to find the database included in this kubernetes cluster.
  
  In docker-compose I could just use the container name and it would automatically route me to the correct one, with kubernetes it does not seem to be the case.
  
  How do I route to specific containers in different pods in Kubernetes? I tried service names, using the namespace set up by the pipeline's admin team (`<POD>`.`<NAMESPACE>`.svc.cluster.local), and an ExternalName, but every time I get the same error: `Error: getaddrinfo ENOTFOUND`
  
  Any advice would be appreciated as I am new to kubernetes.
  
  **Tags:** kubernetes, networking
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-04-28. Score: 4 | Accepted answer
  
  Normally, you access services using the name provided by a `Service` resource.
  
  For example, if I have a `Pod` running Redis, like this:
  
  ```
  apiVersion: v1
  kind: Pod
  metadata:
    labels:
      app: redis
    name: redis
  spec:
    containers:
      - image: docker.io/redis:latest
        name: redis
        ports:
        - containerPort: 6379
          name: redis
  
  ```
  
  I might have a service definition that looks like:
  
  ```
  apiVersion: v1
  kind: Service
  metadata:
    name: redis
  spec:
    selector:
      app: redis
    ports:
    - port: 6379
      targetPort: redis
  
  ```
  
  With these in place, from another `Pod` I can refer to the Redis
  service using the hostname `redis`:
  
  ```
  [root@client /]# redis-cli -h redis
  redis:6379>
  
  ```
  
  ---
  
  The name and port to which we connect is controlled by the `Service`
  object. If instead of the above example I had:
  
  ```
  apiVersion: v1
  kind: Service
  metadata:
    name: bob
  spec:
    selector:
      app: redis
    ports:
    - port: 2000
      targetPort: redis
  
  ```
  
  I would need to connect like this:
  
  ```
  [root@client /]# redis-cli -h bob -p 2000
  bob:2000>
  
  ```
  
  ---
  
  For more information:
  
  * [Service](https://kubernetes.io/docs/concepts/services-networking/service/)
  
  
  ---
  
  