问题描述
使用 az containerapp create --yaml
location: chinanorth3
properties:
environmentId: "/subscriptions/<subscription id>/resourceGroups/<resource group name>/providers/Microsoft.App/managedEnvironments/<environment name>"
configuration:
ingress:
external: true
targetPort: 8080
registries:
- server: <ARC Name>.azurecr.cn
identity: <user identity resource id>"
template:
containers:
- name: myapp
image: <Image URL:Tags>
resources:
cpu: 0.5
memory: 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 : NativeCommandError
ERROR: 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"})
错误截图:

基于以上问题,应该如何解决呢?
问题解答
在使用 az containerapp create --yaml

az containerapp create --name
--resource-group --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就可以了。

参考资料
[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
正在加载评论...