通过 ARM 使用 Azure 容器实例来创建不确定数量的容器
Use Azure Container Instances via ARM to create an indeterminate number of containers
我正在尝试通过 ARM 模板部署 Azure 存储帐户以及数量不确定的 table。
由于 MS 尚未为 ARM 提供 tables 资源类型,我改为使用 Azure 容器实例启动容器 运行ning azure-cli
,然后创建table 那样。
正如您在下面的示例中看到的,我使用 property iteration 创建多个容器 - 每个 table 一个。这似乎一直有效,直到要创建的 table 数量发生变化,然后我开始出现错误。
The updates on container group 'your-aci-instance' are invalid. If you are going to update the os type, restart policy, network profile, CPU, memory or GPU resources for a container group, you must delete it first and then create a new one.
我明白它在说什么,但我觉得很奇怪,您可以创建一个容器组但不更改其中的容器组。
由于 ARM 不允许您删除资源,我必须在我的部署过程中添加一个手动步骤以确保 ACI 不存在,这并不是我们想要的。
同样不可取的是使用 resource iteration 创建多个 ACI - 可能会有许多 ACI 散落在资源组中,这些 ACI 将永远不会被再次使用。
是否有一些我还不知道的 ARM 魔法可以帮助我实现满足以下条件的 tables 的创建?
- 只创建了一个 ACI。
- 要创建的 table 的数量可以更改。
备注
我曾尝试使用 variable iteration 为单个容器创建单个 'command' 数组,但似乎 ACI 将所有命令视为一个衬里,因此这导致了错误。
进一步阅读表明,容器启动时只能运行一个命令。
当前尝试
这是我的 ARM 模板中的一个片段,展示了我如何使用 property iteration 来尝试实现我的目标。
{
"condition": "[not(empty(variables('tables')))]",
"type": "Microsoft.ContainerInstance/containerGroups",
"name": "[parameters('containerInstanceName')]",
"apiVersion": "2018-10-01",
"location": "[resourceGroup().location]",
"properties": {
"copy": [
{
"name": "containers",
"count": "[max(length(variables('tables')), 1)]",
"input": {
"name": "[toLower(variables('tables')[copyIndex('containers')])]",
"properties": {
"image": "microsoft/azure-cli",
"command": [
"az",
"storage",
"table",
"create",
"--name",
"[variables('tables')[copyIndex('containers')]]"
],
"environmentVariables": [
{
"name": "AZURE_STORAGE_KEY",
"value": "[listkeys(parameters('storageAccount_Application_Name'), '2019-04-01').keys[0].value]"
},
{
"name": "AZURE_STORAGE_ACCOUNT",
"value": "[parameters('storageAccount_Application_Name')]"
},
{
"name": "DATETIME",
"value": "[parameters('dateTime')]"
}
],
"resources": {
"requests": {
"cpu": "1",
"memoryInGb": "1.5"
}
}
}
}
}
],
"restartPolicy": "OnFailure",
"osType": "Linux"
},
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccount_Application_Name'))]"
],
"tags": {
"displayName": "Application Storage Account - Tables",
"Application": "[parameters('tagApplication')]",
"environment": "[parameters('tagEnvironment')]",
"version": "[parameters('tagVersion')]"
}
}
如果它说该字段是不可变的 - 是的,您真的无能为力。您始终可以为该容器实例创建一个唯一的名称并使用完整的部署模式,并且只将 ACI 部署到这个特定的资源组,这样它将始终只有这个 ACI 实例,其他实例将被删除并且它将解决不变性问题。
您可以从模板内部调用 azure 函数(HTTP 触发器)并传入要创建的存储表的名称,它会执行此操作,例如。
但无论哪种方式都是黑客。
我正在尝试通过 ARM 模板部署 Azure 存储帐户以及数量不确定的 table。
由于 MS 尚未为 ARM 提供 tables 资源类型,我改为使用 Azure 容器实例启动容器 运行ning azure-cli
,然后创建table 那样。
正如您在下面的示例中看到的,我使用 property iteration 创建多个容器 - 每个 table 一个。这似乎一直有效,直到要创建的 table 数量发生变化,然后我开始出现错误。
The updates on container group 'your-aci-instance' are invalid. If you are going to update the os type, restart policy, network profile, CPU, memory or GPU resources for a container group, you must delete it first and then create a new one.
我明白它在说什么,但我觉得很奇怪,您可以创建一个容器组但不更改其中的容器组。
由于 ARM 不允许您删除资源,我必须在我的部署过程中添加一个手动步骤以确保 ACI 不存在,这并不是我们想要的。
同样不可取的是使用 resource iteration 创建多个 ACI - 可能会有许多 ACI 散落在资源组中,这些 ACI 将永远不会被再次使用。
是否有一些我还不知道的 ARM 魔法可以帮助我实现满足以下条件的 tables 的创建?
- 只创建了一个 ACI。
- 要创建的 table 的数量可以更改。
备注
我曾尝试使用 variable iteration 为单个容器创建单个 'command' 数组,但似乎 ACI 将所有命令视为一个衬里,因此这导致了错误。
进一步阅读表明,容器启动时只能运行一个命令。
当前尝试
这是我的 ARM 模板中的一个片段,展示了我如何使用 property iteration 来尝试实现我的目标。
{
"condition": "[not(empty(variables('tables')))]",
"type": "Microsoft.ContainerInstance/containerGroups",
"name": "[parameters('containerInstanceName')]",
"apiVersion": "2018-10-01",
"location": "[resourceGroup().location]",
"properties": {
"copy": [
{
"name": "containers",
"count": "[max(length(variables('tables')), 1)]",
"input": {
"name": "[toLower(variables('tables')[copyIndex('containers')])]",
"properties": {
"image": "microsoft/azure-cli",
"command": [
"az",
"storage",
"table",
"create",
"--name",
"[variables('tables')[copyIndex('containers')]]"
],
"environmentVariables": [
{
"name": "AZURE_STORAGE_KEY",
"value": "[listkeys(parameters('storageAccount_Application_Name'), '2019-04-01').keys[0].value]"
},
{
"name": "AZURE_STORAGE_ACCOUNT",
"value": "[parameters('storageAccount_Application_Name')]"
},
{
"name": "DATETIME",
"value": "[parameters('dateTime')]"
}
],
"resources": {
"requests": {
"cpu": "1",
"memoryInGb": "1.5"
}
}
}
}
}
],
"restartPolicy": "OnFailure",
"osType": "Linux"
},
"dependsOn": [
"[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccount_Application_Name'))]"
],
"tags": {
"displayName": "Application Storage Account - Tables",
"Application": "[parameters('tagApplication')]",
"environment": "[parameters('tagEnvironment')]",
"version": "[parameters('tagVersion')]"
}
}
如果它说该字段是不可变的 - 是的,您真的无能为力。您始终可以为该容器实例创建一个唯一的名称并使用完整的部署模式,并且只将 ACI 部署到这个特定的资源组,这样它将始终只有这个 ACI 实例,其他实例将被删除并且它将解决不变性问题。
您可以从模板内部调用 azure 函数(HTTP 触发器)并传入要创建的存储表的名称,它会执行此操作,例如。
但无论哪种方式都是黑客。