当前位置: 首页 > news >正文

【Azure Container App】使用 yaml 部署Container App时候遇见 400 Bad Request 错误

问题描述

使用 az containerapp create --yaml <file> 创建 Azure Container App 时, yaml 文件中只包含简单的信息,结果遇见不可理喻/无法正常分析的 400 Bad Request问题。
location: chinanorth3
properties:environmentId: "/subscriptions/<subscription id>/resourceGroups/<resource group name>/providers/Microsoft.App/managedEnvironments/<environment name>"configuration:ingress:external: truetargetPort: 8080registries:- server: <ARC Name>.azurecr.cnidentity: <user identity resource id>"template:containers:- name: myappimage: <Image URL:Tags>resources:cpu: 0.5memory: 1Gi

在实际的操作中的错误信息信息:

az : WARNING: The behavior of this command has been altered by the following extension: containerapp
At line:3 char:1
+ az containerapp create   --name my-container-app-0430   --resource-gr ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+ CategoryInfo          : NotSpecified: (WARNING: The be...n: containerapp:String) [], RemoteException+ FullyQualifiedErrorId : NativeCommandErrorERROR: Bad Request({"type":"https://tools.ietf.org/html/rfc9110#section-15.5.1","title":"One or more validation errors occurred.","status":400,"errors":{"$":["The JSON value could not be converted to System.Boolean. Path: $ | LineNumber: 0 | BytePositionInLine: 
4."]},"traceId":"00-*********-********-01"})

错误截图:

image
基于以上问题,应该如何解决呢?

 

问题解答

在使用 az containerapp create --yaml <file> 创建 Azure Container App 时,CLI 扩展会将完整的内部模型对象序列化后作为 HTTP PUT 请求体发送给 Azure Resource Manager(ARM)。
该序列化行为存在缺陷:即使 YAML 中未设置的可选字段也会被包含进请求体,并被显式赋值为 null
这种行为导致 ARM 在反序列化阶段出现类型转换错误,尤其是当某些字段在后端模型中为非空类型(例如 System.Boolean)时,ARM 尝试将 null 转换为布尔值会直接失败,最终返回 HTTP 400 错误。
 
通过 --debug 日志可以观察到请求体中包含大量 null 字段。
 
"allowInsecure": null 这一个字段正是问题的关键,因为 ARM 期望其为布尔类型而非 null,从而导致整体请求失败。
 
image
 

 az containerapp create   --name <xxxxx>  --resource-group <xxxxx>  --yaml "containerapp.yaml" --debug  

 ( 为  az containerapp create 添加 --debug , 打印出完整的请求日志,就可以发现HTTP请求body中,很多字段默认添加了 “null” 值 )

补充说明:

  • az containerapp update --yaml 命令可以正常执行,因为它使用的是 HTTP PATCH,仅提交变更字段(不包含 null 字段)。
  • az deployment group create(Bicep/ARM 模板)也不存在该问题,因为其序列化过程不会注入 null 字段。

 

解决方案

在ACA的yaml文件中,指定 allowInsecure 的值为false就可以了。

image

 

参考资料

[containerapp] az containerapp create --yaml injects null fields into PUT request body, causing HTTP 400 (System.Boolean conversion error) #9729 : https://github.com/Azure/azure-cli-extensions/issues/9729

Configure ingress for your app in Azure Container Apps : https://learn.microsoft.com/en-us/azure/container-apps/ingress-how-to?pivots=azure-cli

Azure Container Apps ARM and YAML template specifications : https://learn.microsoft.com/en-us/azure/container-apps/azure-resource-manager-api-spec?tabs=yaml

 

http://www.jsqmd.com/news/727356/

相关文章:

  • 合肥装修公司排行:5家本土实力品牌实测盘点 - 奔跑123
  • 保姆级教程:在Ubuntu 20.04上配置ROS Noetic+YOLOv5_ROS实现Gazebo仿真抓取
  • 用蒲公英X1旁路组网,零成本打通办公室和家庭NAS(附小米路由器刷Padavan静态路由配置)
  • Cesium-Wind:3步实现3D风场可视化,让大气流动看得见的终极指南
  • GitHub中文界面终极指南:3分钟免费搞定GitHub全面汉化!
  • FitNesse 版本控制与历史管理:团队协作的最佳实践
  • 国内行车开关核心供应商技术实力实测对比 - 奔跑123
  • Rusted PackFile Manager:Total War模组制作的终极一站式解决方案
  • 合肥老房翻新公司排行:5家合规机构实测对比 - 奔跑123
  • Hermes Agent 自进化架构的源码级拆解
  • ChatGPT Team运营工作台:一体化账号管理与自动化分发系统深度解析
  • 别再忍受默认配色了!手把手教你用VSCode的C/C++ Theme插件打造专属护眼主题
  • MPC-BE:Windows上最强大的开源媒体播放器完全指南
  • OpenRW状态机与游戏流程:从菜单到游戏内状态的完整管理
  • 别再只会用ID批量更新了!手把手教你扩展MyBatis-Plus的updateBatchByColumn方法
  • [算法] 扩展中国剩余定理(exCRT)
  • 构建个人技能库:用YAML+GitHub Actions打造可验证的技术图谱
  • smcFanControl:让你的Intel Mac保持凉爽的智能风扇控制解决方案
  • 从零开始:Docker 部署 Milvus 向量数据库并接入 Attu 与 pymilvus 的全流程指南
  • Arm CoreLink GIC-600AE中断控制器架构与编程详解
  • FreeMove终极指南:如何高效迁移C盘大文件而不破坏程序功能?
  • PHP修行之路:从零开始学习PHP的终极完整指南
  • python进程和线程(二、主要讲解进程)
  • Sakana!石蒜模拟器物理引擎优化:惯性、衰减与粘性参数的数学原理与调优技巧
  • 别再乱写HLSL了!Unity URP Shader中Core.hlsl的正确打开方式
  • TensorRT 10.0深度学习推理优化与部署实战
  • 通过用量看板观测不同模型调用成本实现精细化预算管理
  • 大模型的短期记忆和长期记忆系统:做 RAG、Agent、知识库前的必修课
  • 物联网开发工具链容器化实践:基于Docker Compose的一站式部署方案
  • 对比直接使用原厂 API 体验 Taotoken 在多模型切换上的便捷性