首页 > 解决方案 > 在 Google App Engine 中部署 python 时出错

问题描述

我正在尝试部署 python 应用程序,但收到以下错误消息:

错误:(gcloud.app.deploy)错误响应:[4]您的部署未能在分配的时间内变得健康,因此被回滚。如果您认为这是一个错误,请尝试调整“readiness_check”部分中的“app_start_timeout_sec”设置。

我的 app.yaml 是:

runtime: python
runtime_config:
  python_version: 3
env: flex
service: newservice
handlers:
- url: /
  script: hello.py

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

我相信问题与 yaml 文件有关,因为我之前部署了一个示例应用程序没有问题(在我的 yaml 上使用入口点),然后当我添加一个新的 python 脚本并在 yaml 文件中引用它时(使用处理程序,运行我的消息块)我开始收到此错误。

编辑:在 GAEFan 的回答之后,我的问候包含了一个 readiness_check 处理程序:

def post():
    self.response.headers['Content-Type'] = 'application/json'   
    obj = {
      'status': 200, 
    } 
    self.response.out.write(json.dumps(obj))

webapp2.WSGIApplication([
    ('/readiness_check', post())
], debug=True)

标签: pythongoogle-app-enginedeploymentcgi

解决方案


Readiness checks默认启用。因此,您应该为它们设置 url 处理程序。在这种情况下,GAE 正在向 发送请求/readiness_check,但您app.yaml没有该 url 的处理程序。尝试这个:

handlers:
- url: /.*
  script: hello.py

并确保 url 返回一个200或类似的响应。要自定义就绪检查:

readiness_check:
  path: "/readiness_check"
  check_interval_sec: 5
  timeout_sec: 4
  failure_threshold: 2
  success_threshold: 2
  app_start_timeout_sec: 300

或者:

liveness_check:
  path: "/liveness_check"
  check_interval_sec: 30
  timeout_sec: 4
  failure_threshold: 2
  success_threshold: 2

详情见: https ://cloud.google.com/appengine/docs/flexible/custom-runtimes/configuring-your-app-with-app-yaml#legacy_health_checks


推荐阅读