我有一个简单的Flask应用。当我通过端口转发将HTTP Post请求直接发送到服务时,它工作正常。
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()
我还在nginx容器中有一个简单的index.html文件,该文件位于端口80上。它对“ / upload”执行ajax POST请求。如果您查看入口控制器,应该将其转换为端口5000请求并去除“上传” 烧瓶应用程序在端口5000上投放
这里是入口控制器:
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
为了完整起见,表情符号后端服务:
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
我得到了一个502错误的网关,没有任何指示,只是入口日志确实说了这一点:
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/"
“ http://172.17.0.4:5000/”是emoji后端服务的正确端点和端口。
答案 0 :(得分:2)
添加以下行进行修复:
app.run(debug=True,host='0.0.0.0',port=5000)
但是,我花了一些时间才弄清楚,因为起初我尝试重新部署时,我的docker映像没有更新。