<p>I have a scenario in which I have deployed multiple containers in one pod but having same image (having different commands and args for the internal logic) which listens to port 80 as:</p>
<pre><code>template: {
  spec: {
   containers: [
     {
      name: container1,
      image: image1,
      command: [...],
      args: [...],
      imagePullPolicy: IfNotPresent,
      ports: [
        {
          name: port1,
          containerPort: 80,
        },
      ],
      .............
    },
    {
      name: container2,
      image: image1,
      command: [...],
      args: [...],
      imagePullPolicy: IfNotPresent,
      ports: [
        {
          name: port2,
          containerPort: 80,
        },
      ],
      ------------
    }

       ]
     }
  }
</code></pre>
<p>A service having multiple ports pointing to those containers like:</p>
<pre><code>spec: {
      type: ClusterIP,
      ports: [
      {
      port: 7000,
      targetPort: port1,
      protocol: 'TCP',
      name: port1,
    },
    {
      port: 7001,
      targetPort: port2,
      protocol: 'TCP',
      name: port2,
    } 
   ]
}
</code></pre>
<p>The problem here is service port 7000 and 7001 both seems to be pointing to container1 (might be due to both are identical images with same container port) but I want 7000 to point to container1 and 7001 to container2. Is their any way to do so?</p>

Yashasvi Raj Pant
<p>Yes, you can very simply use different port numbers for <code>port1</code> and <code>port2</code>. It will fix the problem.</p>
<p>You have to understand that generally it is not recommended to have multiple containers in the same pod, and your case here is a good example of why. The port numbers overlap, and container1 starts first in the pod, which binds the port 80 and doesn't allow container2 to use the same port number, hence incoming requests are all going to container1.</p>
<p>Edit: Having identical images is of no consequence here since the issue is with the port numbers.</p>
