python flask-restful 部署在 google 云引擎中

python flask-restful deployment in google cloud engine

我是第一次将 Python 应用程序部署到 GAE 中,它使用 Flask-restful 作为 REST 服务器,我无法理解如何配置正确部署。

我正在尝试使用最小的烧瓶-restful应用示例minimal.py

from flask import Flask
from flask_restful import Resource, Api

app = Flask(__name__)
api = Api(app)

class HelloWorld(Resource):
    def get(self):
        return {'hello': 'world'}

api.add_resource(HelloWorld, '/')

if __name__ == '__main__':
    app.run(debug=True, host='0.0.0.0')

并且我已经按照以下方式配置了部署 app.yaml 文件,其中网络部分试图授予对 flask-restful 默认 5000 端口的访问权限-restful:

runtime: python
env: flex
entrypoint: python minimal.py

runtime_config:
  python_version: 3

network:
  instance_tag: instance-1
  name: default
  forwarded_ports:
    - 5000

名称默认是我的VPC中配置的唯一网络。

部署说明如下,为了去除我之前做过的试验:

gcloud app deploy --promote --stop-previous-version

因此,当我尝试将 curl 设置为 post 时,我收到 502 错误,我也可以在我的服务器中看到该错误。

我在某处遗漏了一步...可能在 VPC 网络或 app.yaml 配置中,但我现在迷路了...

任何帮助将不胜感激:)

尝试更新 yaml 的配置。

runtime: python
env: flex
entrypoint: gunicorn -b :$PORT minimal:app

runtime_config:
  python_version: 3

manual_scaling:
  instances: 1
resources:
  cpu: 1
  memory_gb: 0.5
  disk_size_gb: 10

参考:https://cloud.google.com/appengine/docs/flexible/python/configuring-your-app-with-app-yaml