GCP中自定义运行时App Engine部署失败求助
GCP App Engine Flex自定义运行时部署失败(Autoscaler内部错误)解决方案
问题描述
部署自定义运行时到GCP App Engine Flex时遭遇内部错误,报错核心指向compute.beta.regionAutoscaler资源的INTERNAL_ERROR:
ERROR: (gcloud.app.deploy) Error Response: [13] Flex operation projects/custom-runtime-app/regions/asia-south1/operations/5f33c87e-b5fc-4896-ad3a-745f014b2d19 error [INTERNAL]: An internal error occurred while processing task /app-engine-flex/insert_flex_deployment/flex_create_resources>2023-08-10T08:04:17.559Z1108.pt.1: Deployment Manager operation custom-runtime-app/operation-1691654658441-6028d0affbfd9-b08c5121-7ca0a212 errors: [code: "RESOURCE_ERROR" location: "/deployments/aef-default-20230810t133154/resources/aef-default-20230810t133154" message: "{\"ResourceType\":\"compute.beta.regionAutoscaler\",\"ResourceErrorCode\":\"INTERNAL_ERROR\",\"ResourceErrorMessage\":\"INTERNAL_ERROR\"}" ]
当前配置:
app.yaml
runtime : custom env : flex
Dockerfile
FROM python WORKDIR ./ ADD ./main.py ./ CMD [ "python","./main.py" ]
排查与修复步骤
显式指定Python版本
基础镜像python默认拉取最新版本,可能与App Engine Flex环境存在兼容性问题。建议指定具体稳定版本,同时使用绝对路径作为工作目录:FROM python:3.11-slim WORKDIR /app COPY ./main.py . CMD ["python", "./main.py"]添加健康检查配置
App Engine Flex需要应用提供健康检查端点,否则自动扩缩容组件无法正常初始化。在app.yaml中添加健康检查规则:runtime: custom env: flex health_check: enable_health_check: True check_interval_sec: 5 timeout_sec: 4 unhealthy_threshold: 2 healthy_threshold: 2同时在
main.py中实现默认健康检查端点/_ah/health,并确保应用绑定8080端口(App Engine Flex默认监听端口):from flask import Flask app = Flask(__name__) @app.route('/_ah/health') def health_check(): return "OK", 200 @app.route('/') def hello(): return "Hello World!" if __name__ == '__main__': app.run(host='0.0.0.0', port=8080)临时禁用自动扩缩容
若自动扩缩容组件是故障源头,可先在app.yaml中禁用该功能,验证基础部署是否正常:runtime: custom env: flex automatic_scaling: enabled: False部署成功后再逐步启用并调整扩缩容配置。
更换部署区域
部分区域可能存在临时服务故障,尝试切换到稳定区域(如us-central1、europe-west1):gcloud app deploy --region=us-central1检查权限与API状态
确认部署账号拥有App Engine Admin和Compute Admin权限,同时确保Compute Engine API和App Engine Flexible Environment API已启用。
内容的提问来源于stack exchange,提问作者ramsey
相关产品推荐
相关产品推荐

