<p>I'm developing an application that consists of two containers. I want to deploy them in Kubernetes into one Pod, since I want the two services to be behind one IP address. However, I'm having a hard time trying to connect the Kubernetes Services with the containers.</p>
<p>How could I write a <code>deployment.yml</code> file, so that when the user calls a <code>x.x.x.x:port1</code>, the request is forwarded to the first container, and when the <code>x.x.x.x:port2</code> is called, the request is forwarded to the second container. How could I specify the Services?</p>
<p>Here's what I have until now:</p>
<pre><code>apiVersion:v1
kind: Pod
metadata:
  name: my_app
spec:
  containers:
  - name: first_container
    image: first_image
  
  - name: second_container
    image: second_image
---
apiVersion: v1
kind: Service
...
</code></pre>

<p>In your containers section you need to define a containerPort for each:</p>

<pre><code>  containers:
  - name: first_container
    image: first_image
    ports:
    - containerPort: port1
  - name: second_container
    image: second_image
    ports:
    - containerPort: port2
</code></pre>

<p>And then in the ports section of the service definition you need to point the targetPorts of the service at those ports like in <a href="https://stackoverflow.com/a/42272547/9705485">https://stackoverflow.com/a/42272547/9705485</a></p>
