你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

Azure 容器实例中的可靠性

重要

此功能目前以预览版提供。 需同意补充使用条款才可使用预览版。

本文介绍 Azure 容器实例 (ACI) 中的可靠性支持,并介绍可用性区域的区域内复原能力以及关于灾难恢复的信息。 有关 Azure 中可靠性的更详细概述,请参阅 Azure 可靠性

可用性区域支持

Azure 可用性区域是每个 Azure 地区内的至少三个在物理上独立的数据中心组。 每个区域中的数据中心都配备了独立的电源、冷却系统和网络基础结构。 在本地区域发生故障的情况下,设计可用性区域,以便一个区域受到影响时,其余两个区域支持区域服务、容量和高可用性。

故障范围包括软件和硬件故障,以及地震、洪水和火灾等事件。 容错是通过 Azure 服务的冗余和逻辑隔离来实现的。 有关 Azure 中可用性区域的详细信息,请参阅地区和可用性区域

已启用 Azure 可用性区域的服务旨在提供适当级别的可靠性和灵活性。 可以通过两种方式进行相关配置。 可以采用区域冗余配置,实现跨区域自动复制,也可以采用区域性配置,将实例固定到特定区域。 还可以将这些方法结合。 有关区域与区域冗余体系结构的详细信息,请参阅有关使用可用性区域和区域的建议

Azure 容器实例支持区域容器组部署,这表示实例将固定到特定的自选可用性区域。 可用性区域在容器组级别指定。 容器组内的容器不能具有唯一的可用性区域。 要更改容器组的可用性区域,必须删除容器组,然后使用新的可用性区域创建另一个容器组。

先决条件

重要

此功能目前不适用于 Azure 门户。

  • 大多数 ACI 可用于 Linux 和 Windows Server 2019 容器组的区域都支持区域容器组部署。 有关详细信息,请参阅区域和资源可用性
  • 如果使用 Azure CLI,请确保已安装 2.30.0 版或更高版本。
  • 如果使用 PowerShell,请确保已安装 2.1.1-preview 版或更高版本。
  • 如果使用 Java SDK,请确保已安装 2.9.0 版或更高版本。
  • 可用性区域支持仅适用于 ACI API 09-01-2021 版或更高版本。

重要

包含 GPU 资源的容器组目前不支持可用性区域。

可用性区域重新部署和迁移

要更改容器组的可用性区域,必须删除容器组,然后使用新的可用性区域创建另一个容器组。

创建启用可用性区域的资源

若要创建启用了可用性区域的容器实例资源,需要使用 Azure 资源管理器 (ARM) 模板部署容器组。

注意

本文中的示例已针对 Bash shell 设置了格式。 如果希望使用另一个 shell,请相应地调整行继续符。

要使用 ARM 部署容器:

  1. 将以下 JSON 复制粘贴到名为 azuredeploy.json 的新文件中。 此示例模板将包含单个容器的容器组部署到美国东部的可用性区域 1。

    {
        "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
        "contentVersion": "1.0.0.0",
        "metadata": {
            "_generator": {
                "name": "bicep",
                "version": "0.4.1.14562",
                "templateHash": "12367894147709986470"
            }
        },
        "parameters": {
            "name": {
                "type": "string",
                "defaultValue": "acilinuxpublicipcontainergroup",
                "metadata": {
                    "description": "Name for the container group"
                }
            },
            "image": {
                "type": "string",
                "defaultValue": "mcr.microsoft.com/azuredocs/aci-helloworld",
                "metadata": {
                    "description": "Container image to deploy. Should be of the form repoName/imagename:tag for images stored in public Docker Hub, or a fully qualified URI for other registries. Images from private registries require additional registry credentials."
                }
            },
            "port": {
                "type": "int",
                "defaultValue": 80,
                "metadata": {
                    "description": "Port to open on the container and the public IP address."
                }
            },
            "cpuCores": {
                "type": "int",
                "defaultValue": 1,
                "metadata": {
                    "description": "The number of CPU cores to allocate to the container."
                }
            },
            "memoryInGb": {
                "type": "int",
                "defaultValue": 2,
                "metadata": {
                    "description": "The amount of memory to allocate to the container in gigabytes."
                }
            },
            "restartPolicy": {
                "type": "string",
                "defaultValue": "Always",
                "allowedValues": [
                    "Always",
                    "Never",
                    "OnFailure"
                ],
                "metadata": {
                    "description": "The behavior of Azure runtime if container has stopped."
                }
            },
            "location": {
                "type": "string",
                "defaultValue": "eastus",
                "metadata": {
                    "description": "Location for all resources."
                }
            }
        },
        "functions": [],
        "resources": [
            {
                "type": "Microsoft.ContainerInstance/containerGroups",
                "apiVersion": "2021-09-01",
                "zones": [
                    "1"
                ],
                "name": "[parameters('name')]",
                "location": "[parameters('location')]",
                "properties": {
                    "containers": [
                        {
                            "name": "[parameters('name')]",
                            "properties": {
                                "image": "[parameters('image')]",
                                "ports": [
                                    {
                                        "port": "[parameters('port')]",
                                        "protocol": "TCP"
                                    }
                                ],
                                "resources": {
                                    "requests": {
                                        "cpu": "[parameters('cpuCores')]",
                                        "memoryInGB": "[parameters('memoryInGb')]"
                                    }
                                }
                            }
                        }
                    ],
                    "osType": "Linux",
                    "restartPolicy": "[parameters('restartPolicy')]",
                    "ipAddress": {
                        "type": "Public",
                        "ports": [
                            {
                                "port": "[parameters('port')]",
                                "protocol": "TCP"
                            }
                        ]
                    }
                }
            }
        ],
        "outputs": {
            "containerIPv4Address": {
                "type": "string",
                "value": "[reference(resourceId('Microsoft.ContainerInstance/containerGroups', parameters('name'))).ipAddress.ip]"
            }
        }
    }
    
  2. 使用 [az group create][availability-zones-group-create] 命令创建资源组:

    az group create --name myResourceGroup --location eastus
    
  3. 使用 az deployment group create 命令部署模板:

    az deployment group create \
      --resource-group myResourceGroup \
      --template-file azuredeploy.json
    
  4. 要验证已成功部署到可用性区域中的容器组,请使用 az container show 命令查看容器组详细信息:

    az containershow --name acilinuxcontainergroup --resource-group myResourceGroup
    

区域故障转移支持

容器实例的容器组分配至单个可用性区域。 因此,同一区域的任何其他可用性区域中发生的中断不会影响该组容器实例

但如果容器组的可用性区域中发生中断,该组内的所有容器实例可能都会出现停机。

为了避免容器实例停机,建议在给定区域中至少跨两个不同可用性区域创建两个容器组。 这样可以确保在该区域中的任一区域发生服务中断时,容器实例资源都能保持正常运行。

灾难恢复

当整个 Azure 区域或数据中心遭遇停机时,任务关键型代码需要在不同的区域内继续进行处理。 使用区域配置部署的 Azure 容器实例在特定区域内的特定区域中运行。 没有可用的内置冗余。 为了避免在出现区域范围的服务中断时丢失执行,可以在其他区域以冗余方式部署容器实例。

后续步骤