0

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

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

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

我已经查阅了文档,但那里似乎没有任何关于此的内容。

反正有没有告诉容器实例总是启动?

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

{
  "$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"
      }
    }
  ]
}
4

1 回答 1

0

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

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

于 2019-02-19T11:32:11.177 回答