<p>So, I am trying to deploy a personal website app and expose it to a local domain (for now) but <strong>I am always getting a 502 Bad Gateway from my nginx-ingress-controller</strong>.
So, for such task I have built 3 files: <code>deployment.yaml</code>, <code>service.yaml</code> and <code>ingress.yaml</code>:</p>
<pre><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: website-deployment
  labels:
    app: website
spec:
  replicas: 1
  selector:
    matchLabels:
      app: website
  template:
    metadata:
      labels:
        app: website
    spec:
      containers:
      - name: website
        image: jotinha2014/private
        ports:
        - containerPort: 55004
</code></pre>
<pre><code>    apiVersion: v1
    kind: Service
    metadata:
      name: website-service
    spec:
      selector:
        app: website
      ports:
        - protocol: TCP
          port: 80
          targetPort: 55004
      type: ClusterIP
</code></pre>
<pre><code>apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: website-ingress
  namespace: default
  annotations:
    nginx.ingress.kubernetes.io/service-upstream: &quot;true&quot;
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - host: rabanadas.eu
    http:
      paths:
      - path: /
        pathType: Prefix
        backend:
          service:
            name: website-service
            port:
              number: 80
</code></pre>
<p>Here are some logs from my nginx-ingress-controller:</p>
<pre><code>2021/01/03 01:13:31 [error] 1371#1371: *34677 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.64.1, server: rabanadas.eu, request: &quot;GET / HTTP/1.1&quot;, upstream: &quot;http://10.106.8.10:80/&quot;, host: &quot;rabanadas.eu&quot;
2021/01/03 01:13:31 [error] 1371#1371: *34677 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.64.1, server: rabanadas.eu, request: &quot;GET / HTTP/1.1&quot;, upstream: &quot;http://10.106.8.10:80/&quot;, host: &quot;rabanadas.eu&quot;
2021/01/03 01:13:31 [error] 1371#1371: *34677 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.64.1, server: rabanadas.eu, request: &quot;GET / HTTP/1.1&quot;, upstream: &quot;http://10.106.8.10:80/&quot;, host: &quot;rabanadas.eu&quot;
192.168.64.1 - - [03/Jan/2021:01:13:31 +0000] &quot;GET / HTTP/1.1&quot; 502 552 &quot;-&quot; &quot;Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36&quot; 474 0.000 [default-website-service-80] [] 10.106.8.10:80, 10.106.8.10:80, 10.106.8.10:80 0, 0, 0 0.000, 0.000, 0.000 502, 502, 502 dff7944bbbc17be35584fee465d047d2
W0103 01:15:52.298006       8 warnings.go:67] networking.k8s.io/v1beta1 Ingress is deprecated in v1.19+, unavailable in v1.22+; use networking.k8s.io/v1 Ingress
</code></pre>
<p>Right now I am using minikube and, as such, my nginx-ingress-controller was configure just by adding it as <strong>addon</strong>.
I suspect that the problem is with my ingress configuration because I've already port-forwarded the pod deployed and the website is showing as it is supposed on the right port.</p>
<p>As requested, here are my website pod details:</p>
<pre><code>Name:         website-deployment-69f57fc45-l4th9
Namespace:    default
Priority:     0
Node:         minikube/192.168.64.5
Start Time:   Sun, 03 Jan 2021 00:53:16 +0000
Labels:       app=website
              pod-template-hash=69f57fc45
Annotations:  &lt;none&gt;
Status:       Running
IP:           172.17.0.2
IPs:
  IP:           172.17.0.2
Controlled By:  ReplicaSet/website-deployment-69f57fc45
Containers:
  website:
    Container ID:   docker://eae48617da80f3ac4832695535432581746d925fc497066a5fd8a707b3020a88
    Image:          jotinha2014/private
    Image ID:       docker-pullable://jotinha2014/private@sha256:0a9573429315745eae0a33339021c82db2e92e0ba35ca652aa20482af31f1219
    Port:           55004/TCP
    Host Port:      0/TCP
    State:          Running
      Started:      Sun, 03 Jan 2021 00:53:18 +0000
    Ready:          True
    Restart Count:  0
    Environment:    &lt;none&gt;
    Mounts:
      /var/run/secrets/kubernetes.io/serviceaccount from default-token-j8pzx (ro)
Conditions:
  Type              Status
  Initialized       True
  Ready             True
  ContainersReady   True
  PodScheduled      True
Volumes:
  default-token-j8pzx:
    Type:        Secret (a volume populated by a Secret)
    SecretName:  default-token-j8pzx
    Optional:    false
QoS Class:       BestEffort
Node-Selectors:  &lt;none&gt;
Tolerations:     node.kubernetes.io/not-ready:NoExecute op=Exists for 300s
                 node.kubernetes.io/unreachable:NoExecute op=Exists for 300s
Events:          &lt;none&gt;
</code></pre>
<p>Thanks in advance fo any help.</p>

<p>As per the comments; The <code>targetPort</code> in the <code>Service</code> manifest, and the <code>containerPort</code> in the <code>Deployment</code> manifest need to match the port that the server inside the container is listening on.</p>
<p>As nginx by default listens on port 80, these should be changed to port 80.
Otherwise, the server in the container should be changed to listen on a different port. For nginx this can be done with an nginx.conf file, or by setting an <code>NGINX_PORT</code> environment variable. See <a href="https://hub.docker.com/_/nginx" rel="nofollow noreferrer">https://hub.docker.com/_/nginx</a> for details.</p>
<p>Usually, you'll run one container per pod, so changing the port to something other than 80 is rarely needed.</p>
