docker Google App Engine部署失败,原因是就绪检查失败

7xllpg7q  于 2023-04-20  发布在  Docker
关注(0)|答案(3)|浏览(131)

自定义应用程序引擎环境无法启动,似乎是由于健康检查失败。该应用程序有一些自定义依赖项(例如PostGIS,GDAL),因此在应用程序引擎映像之上有几层。它成功构建并在Docker容器中本地运行。

ERROR: (gcloud.app.deploy) Error Response: [4] Your deployment has failed to become healthy in the allotted time and therefore was rolled back. If you believe this was an error, try adjusting the 'app_start_timeout_sec' setting in the 'readiness_check' section.

Dockerfile如下所示(注意:在docker-compose.ymlapp.yaml中没有定义CMD作为入口点):

FROM gcr.io/google-appengine/python
ENV PYTHONUNBUFFERED 1
ENV DEBIAN_FRONTEND noninteractive

RUN apt -y update && apt -y upgrade\
    && apt-get install -y software-properties-common \
    && add-apt-repository -y ppa:ubuntugis/ppa \
    && apt -y update \
    && apt-get -y install gdal-bin libgdal-dev python3-gdal  \ 
    && apt-get autoremove -y \
    && apt-get autoclean -y \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*

ADD requirements.txt /app/requirements.txt
RUN python3 -m pip install -r /app/requirements.txt 
ADD . /app/
WORKDIR /app

不幸的是,这创建了一个高达1.58GB的映像,但是原始的gcr.iopython映像从1.05GB开始,所以我不认为映像的大小会或应该是一个问题。
使用以下docker-compose.yml配置在本地运行它,很快就能漂亮地启动一个容器:

version: "3"
services:
  web:
    build: .
    command: gunicorn gisapplication.wsgi --bind 0.0.0.0:8080

所以,我希望下面的yaml.app可以做到这一点:

runtime: custom
env: flex
entrypoint: gunicorn -b :$PORT gisapplication.wsgi

beta_settings:
    cloud_sql_instances: <sql-db-connection>

runtime_config:
    python_version: 3

没有运气。因此,根据上面的错误,它似乎与准备就绪检查有关。尝试增加应用程序启动的超时时间(15分钟!)之前似乎有一些issues with health checks,并且回滚到传统的健康检查不是一个解决方案,截至2019年9月。

readiness_check:
    path: "/readiness_check"
    check_interval_sec: 10
    timeout_sec: 10
    failure_threshold: 3
    success_threshold: 3
    app_start_timeout_sec: 900

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

拆分运行状况检查肯定已打开。gcloud beta app describe的输出为:

authDomain: gmail.com
codeBucket: staging.proj-id-000000.appspot.com
databaseType: CLOUD_DATASTORE_COMPATIBILITY
defaultBucket: proj-id-000000.appspot.com
defaultHostname: proj-id-000000.ts.r.appspot.com
featureSettings:
  splitHealthChecks: true
  useContainerOptimizedOs: true
gcrDomain: asia.gcr.io
id: proj-id-000000
locationId: australia-southeast1
name: apps/proj-id-000000
servingStatus: SERVING

这不起作用,所以还尝试增加示例可用的资源,并为1个CPU分配最大内存量(6.1GB):

resources:
    cpu: 1
    memory_gb: 6.1
    disk_size_gb: 10

为了安全起见,我在应用程序中添加了健康检查端点(传统健康检查和分割健康检查)-这是一个Django应用程序,因此这进入了项目的urls.py

path(r'_ah/health/', lambda r: HttpResponse("OK", status=200)),
path(r'readiness_check/', lambda r: HttpResponse("OK", status=200)),
path(r'liveness_check/', lambda r: HttpResponse("OK", status=200)),

因此,当我深入日志时,似乎有一个来自curl用户代理的对/liveness_check的成功请求,但来自GoogleHC代理的对/readiness_check的后续请求返回503(服务不可用)

不久之后(在8个失败的请求之后-为什么是8个?)似乎发送了关闭触发器:

2020-07-05 09:00:02.603 AEST Triggering app shutdown handlers.

我想我已经用尽了解决这个问题的方法,我想知道是否应该把时间花在让事情在Compute/EC2中运行上。

附录

除了链接的SO问题,我还浏览了Google上的问题(herehere

ctzwtxfj

ctzwtxfj1#

您正在将准备就绪检查发送到path: "/readiness_check",但其url处理程序是path(r'readiness_check/'...)
注意处理程序中的尾随斜杠。删除它(或者在readiness_check:的路径中添加一个尾随的斜杠),看看是否可以修复它。我认为这会给予你一个404,但你得到的是一个503,这告诉我你可能有一个更严重的错误。在控制台中单击503左侧的一个箭头,并查看错误消息是什么。您可能需要在控制台中搜索traceback才能看到它。

pxiryf3j

pxiryf3j2#

好吧,谷歌的人也不能帮助解决它,但经过一段史诗般的旅程,通过太多的日志,我设法找出问题是什么:Dockerfile需要一个CMD语句。虽然我假设这就是app.yaml中的entrypoint的用途,但似乎App Engine使用docker run旋转容器。因此,只需将这一行添加到Dockerfile即可修复它:

CMD gunicorn -b :$PORT gisapplication.wsgi

我还恢复了默认的健康检查设置,并能够将健康检查的URL路径从我的应用程序中取出,并让Google base容器提供的默认nginx示例处理这些。

mspsb9vt

mspsb9vt3#

我去修改我的app.yaml像这样:

readiness_check:
  path: "/readiness_check"
  check_interval_sec: 60
  timeout_sec: 20
  failure_threshold: 2
  success_threshold: 2
  app_start_timeout_sec: 600 #-> increase to 3600

liveness_check:
  path: "/liveness_check"
  check_interval_sec: 60
  timeout_sec: 20
  failure_threshold: 2
  success_threshold: 2

根据医生的说法
此外,在了解了日志there之后,在最后一个部署版本上进行过滤,我终于在bash中看到了这个错误消息:
ERROR: (gcloud.app.deploy) Error Response: [4] An internal error occurred while processing task /app-engine-flex/flex_await_healthy/flex_await_healthy>2023-04-15T01:30:41.152Z11154.hx.2: Your deployment has failed to become healthy in the allotted time and therefore was rolled back. If you believe this was an error, try adjusting the 'app_start_timeout_sec' setting in the 'readiness_check' section.
所以上面增加了超时。下面的一行更多关于构建时间超时,这对我来说也没问题,但只是为了确保,在你的.yaml文件中没有任何-步骤,但在CLI中只有这个:
gcloud config set app/cloud_build_timeout 3000 --installation

相关问题