【问题标题】:Container Instance only runs on first deployment from ARM template容器实例仅在从 ARM 模板首次部署时运行
【发布时间】:2019-02-19 19:37:48
【问题描述】:

我正在尝试通过 ARM 模板创建具有文件共享的存储帐户。为此,我创建了存储帐户,然后在容器实例 as described here 中运行 az CLI 命令。

模板部署得很好,但问题是容器只在第一次运行时启动。后续部署不会导致容器实例启动,因此如果文件共享已被删除(人为错误),则不会重新创建。

我无法使用完整的部署,因为资源组中还有其他资源。

我已经咨询了documentation,但那里似乎没有任何相关内容。

有没有办法告诉容器实例总是启动?

这是我正在使用的示例模板 -

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "storageAccountType": {
      "type": "string",
      "defaultValue": "Standard_LRS",
      "allowedValues": [
        "Standard_LRS",
        "Standard_GRS",
        "Standard_ZRS"
      ],
      "metadata": {
        "description": "Storage Account type"
      }
    },
    "storageAccountName": {
      "type": "string",
      "defaultValue": "[uniquestring(resourceGroup().id)]",
      "metadata": {
        "description": "Storage Account Name"
      }
    },
    "fileShareName": {
      "type": "string",
      "metadata": {
        "description": "File Share Name"
      }
    },
    "containerInstanceLocation": {
      "type": "string",
      "defaultValue": "[parameters('location')]",
      "allowedValues": [
        "westus",
        "eastus",
        "westeurope",
        "southeastaisa",
        "westus2"
      ],
      "metadata": {
        "description": "Container Instance Location"
      }
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Location for all resources."
      }
    }
  },
  "variables": {
    "image": "microsoft/azure-cli",
    "cpuCores": "1.0",
    "memoryInGb": "1.5",
    "containerGroupName": "createshare-containerinstance",
    "containerName": "createshare"
  },
  "resources": [
    {
      "type": "Microsoft.Storage/storageAccounts",
      "name": "[parameters('storageAccountName')]",
      "apiVersion": "2017-10-01",
      "location": "[parameters('location')]",
      "sku": {
        "name": "[parameters('storageAccountType')]"
      },
      "kind": "Storage",
      "properties": {}
    },
    {
      "name": "[variables('containerGroupName')]",
      "type": "Microsoft.ContainerInstance/containerGroups",
      "apiVersion": "2018-02-01-preview",
      "location": "[parameters('containerInstanceLocation')]",
      "dependsOn": [
        "[concat('Microsoft.Storage/storageAccounts/', parameters('storageAccountName'))]"
      ],
      "properties": {
        "containers": [
          {
            "name": "[variables('containerName')]",
            "properties": {
              "image": "[variables('image')]",
              "command": [
                "az",
                "storage",
                "share",
                "create",
                "--name",
                "[parameters('fileShareName')]"
              ],
              "environmentVariables": [
                {
                  "name": "AZURE_STORAGE_KEY",
                  "value": "[listKeys(parameters('storageAccountName'),'2017-10-01').keys[0].value]"
                },
                {
                  "name": "AZURE_STORAGE_ACCOUNT",
                  "value": "[parameters('storageAccountName')]"
                }
              ],
              "resources": {
                "requests": {
                  "cpu": "[variables('cpuCores')]",
                  "memoryInGb": "[variables('memoryInGb')]"
                }
              }
            }
          }
        ],
        "restartPolicy": "OnFailure",
        "osType": "Linux"
      }
    }
  ]
}

【问题讨论】:

  • m,如果您尝试更改其中一项设置会怎样?那应该更新它并(希望)重新启动它?
  • 确实如此,但在这种情况下,我不想更改设置。谢谢。
  • 只需创建一个虚拟设置并每次更改它
  • 这将需要在每次部署时进行人工干预,这是我不想要的。我将恢复为运行部署后脚本来创建容器。谢谢。
  • 为什么?你有自动化的

标签: azure azure-container-instances


【解决方案1】:

如果您在使用 az container delete 之间从 Azure 门户或通过 az cli 手动删除 ACI,会怎样。据我了解,Azure 容器实例是一次性的。当我想部署新容器时,我通常只是删除旧容器。当然,这通常由 Jenkins 等 CI&CD 管道完成。

编辑: ARM-template 仅在找不到资源时才启动容器,但因为它确实找到了 ACI,所以它什么也不做。恕我直言,您不应该使用 ARM 模板进行容器管理。

【讨论】:

  • 我发现如果我更改正在运行的命令,容器实例就会启动。在没有发生这种情况的情况下,ARM(错误地 IMO)不会启动它。对于典型的基础设施就足够了,但在这种情况下它是不合适的。我希望 MS 将添加对通过 ARM 配置文件共享的支持,就像它们对 Blob 容器一样。不过,在这种情况下,我将放弃我的努力,因为整个想法是消除同时使用 ARM 和 CLI 的需要,因此必须使用 CLI 删除容器实例失败了。不过感谢您的回答。
  • 您可以尝试通过其他配置技术(如 Terraform)或将 ARM 与创建容器和文件共享的 CI&CD 作业结合使用来解决问题
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-11
  • 1970-01-01
  • 2017-11-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多