<p>I am working on fixing some errors in an existing Kubernetes multi-container one pod deployment. I have part of it fixed; I just am missing the syntax to route the traffic from the 'frontend' container to the 'backend' one.</p>
<p>The YAML file:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: minikube-hello-world
  labels:
    app: hello-world
spec:
  replicas: 1
  selector:
    matchLabels:
      app: hello-world
  template:
    metadata:
      labels:
        app: hello-world
    spec:
      containers:
        - name: hello-world-frontend
          image: frontend:latest
          imagePullPolicy: Never
          ports:
            - containerPort: 80
        - name: hello-world-backend
          image: backend:latest
          imagePullPolicy: Never
          ports:
            - containerPort: 80
---
kind: Service
apiVersion: v1
metadata:
  name: hello-world-service
spec:
  selector:
    app: hello-world
  ports:
  - protocol: TCP
    port: 80
    targetPort: 80
    nodePort: 31443
  type: LoadBalancer
</code></pre>
<p>When I run <strong>minikube service hello-world-service</strong> I get the web page itself, but the backend service doesn't connect correctly, Nginx instead showing a <strong>502 Bad Gateway</strong> error.</p>
<p>I've drilled down into the Kubenetes documentation and I've tried <strong>hostPort</strong> various places but I still don't have it right.</p>
<p>Any help would be much appreciated!</p>

Mark McWiggins
<p>As Christian Altamirano Ayala comments above,</p>
<p>Both containers can't be on the same port. (I should have thought of this.)</p>
<p>I changed the frontend to port 8080:</p>
<pre><code>    spec:
      containers:
        - name: hello-world-frontend
          image: frontend:latest
          imagePullPolicy: Never
          ports:
            - containerPort: 8080
        - name: hello-world-backend
          image: backend:latest
          imagePullPolicy: Never
          ports:
            - containerPort: 80
</code></pre>
<p>And the mapping of the NodePort to 8080 also:</p>
<pre><code>kind: Service
apiVersion: v1
metadata:
  name: hello-world-service
spec:
  selector:
    app: hello-world
  ports:
  - protocol: TCP
    nodePort: 31443
    port: 8080
  type: LoadBalancer
</code></pre>
<p>And this works. Thanks!</p>
