<p>I have a simple Flask app. It worked fine when I connected to it via port-forwarding to send the HTTP Post request directly to the Service.</p>

<pre><code>from flask import Flask, request
import redis
from rq import Queue
from worker import job_worker

UPLOAD_FOLDER = './uploads/'

app = Flask(__name__)

r = redis.Redis()
q = Queue(connection = r)

@app.route('/', methods=['POST'])
def upload():
    scale = int(request.form['scale'])
    q.enqueue(job_worker, scale)
    return ""

if __name__ == "__main__":
    app.run()
</code></pre>

<p>I also have a simple index.html file in an nginx container which is served at port 80. It does an ajax POST request to "/upload". Which if you look at the ingress controller, should convert that to a port 5000 request and strip away the "upload"
The flask app gets served at port 5000</p>

<p>Here is the ingress controller:</p>

<pre><code>apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
  name: emoji-ingress
  annotations:
    nginx.ingress.kubernetes.io/rewrite-target: /
spec:
  rules:
  - http:
      paths:
      - path: /upload
        backend:
          serviceName: emoji-backend
          servicePort: 5000
      - path: /
        backend:
          serviceName: emoji-frontend
          servicePort: 80
</code></pre>

<p>And for completeness, the emoji-backend service:</p>

<pre><code>apiVersion: v1
kind: Service
metadata:
  name: emoji-backend
  labels:
    app: emoji-backend
    tier: backend
spec:
  type: LoadBalancer
  ports:
  - port: 5000
  selector:
    app: emoji-backend
    tier: backend
</code></pre>

<p>I get a 502 bad gateway without really any indication except the ingress log does say this:</p>

<pre><code>2019/09/29 21:41:04 [error] 2021#2021: *78651 connect() failed (111: Connection refused) while connecting to upstream, client: 192.168.64.1, server: _, 
request: "POST /upload HTTP/2.0", upstream: "http://172.17.0.4:5000/", host: "192.168.64.5", referrer: "https://192.168.64.5/"
</code></pre>

<p>"<a href="http://172.17.0.4:5000/" rel="nofollow noreferrer">http://172.17.0.4:5000/</a>" is the correct endpoint and port for the emoji-backend service.</p>

JonathanC
<p>Adding the following line fixed it:</p>

<pre><code>app.run(debug=True,host='0.0.0.0',port=5000)
</code></pre>

<p>However, it took me a while to figure that out because at first when I tried it my docker image was not updating when I re-deployed.</p>
