<p>I'm having trouble setting up my k8s pods exactly how I want. My trouble is that I have multiple containers which listen to the same ports (80,443). In a remote machine, I normally use docker-compose with 'ports - 12345:80' to set this up. With K8s it appears from all of the examples I have found that with a container, the only option is to expose a port, not to proxy it. I know I can use reverse proxies to forward to multiple ports, but that would require the images to use different ports rather than using the same port and having the container forward the requests. Is there a way to do this in k8s?</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  name: backend
spec:
  loadBalancerIP: xxx.xxx.xxx.xxx
  selector:
    app: app
    tier: backend
  ports:
  - protocol: &quot;TCP&quot;
    port: 80
    targetPort: 80
  type: LoadBalancer
</code></pre>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
   name: app-deployment
spec:
  selector:
    matchLabels:
      app: app
      tier: backend
      track: stable
  replicas: 1
  template:
    metadata:
      labels:
        app: app
        tier: backend
        track: stable
    spec:
      containers:
      - name: app
        image: image:example
        ports:
        - containerPort: 80
      imagePullSecrets:
      - name: xxxxxxx
</code></pre>
<p>Ideally, I would be able to have the containers on a Node listening to different ports, which the applications running in those containers continue to listen to 80/443, and my services would route to the correct container as necessary.</p>
<p>My load balancer is working correctly, as is my first container. Adding a second container succeeds, but the second container can't be reached. The second container uses a similar script with different names and a different image for deployment.</p>

Carson
<p>The answer here is adding a service for the pod where the ports are declared. Using Kompose to convert a docker-compose file, this is the result:</p>
<pre><code>apiVersion: v1
kind: Service
metadata:
  annotations:
    kompose.cmd: pathToKompose.exe convert
    kompose.version: 1.21.0 (992df58d8)
  creationTimestamp: null
  labels:
    io.kompose.service: app
  name: app
spec:
  ports:
  - name: &quot;5000&quot;
    port: 5000
    targetPort: 80
  selector:
    io.kompose.service: app
status:
  loadBalancer: {}
</code></pre>
<p>as well as</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    kompose.cmd: pathToKompose.exe convert
    kompose.version: 1.21.0 (992df58d8)
  creationTimestamp: null
  labels:
    io.kompose.service: app
  name: app
spec:
  replicas: 1
  selector:
    matchLabels:
      io.kompose.service: app
  strategy: {}
  template:
    metadata:
      annotations:
        kompose.cmd: pathToKompose.exe convert
        kompose.version: 1.21.0 (992df58d8)
      creationTimestamp: null
      labels:
        io.kompose.service: app
    spec:
      containers:
      - image: image:example
        imagePullPolicy: &quot;&quot;
        name: app
        ports:
        - containerPort: 80
        resources: {}
      restartPolicy: Always
      serviceAccountName: &quot;&quot;
      volumes: null
status: {}

</code></pre>
<p>Some of the fluff from Kompose could be removed, but the relevant answer to this question is declaring the port and target port for the pod in a service, and exposing the targetPort as a containerPort in the deployment for the container.
Thanks to David Maze and GintsGints for the help!</p>
