将异常检测器单变量容器部署到 Azure 容器实例

重要

从 2023 年 9 月 20 日开始,将无法创建新的异常检测器资源。 异常检测器服务将于 2026 年 10 月 1 日停用。

了解如何将 Azure AI 服务异常检测器容器部署到 Azure 容器实例。 此过程演示如何创建异常探测器资源。 然后讨论如何拉取关联的容器映像。 最后,我们重点介绍了从浏览器中执行这两个业务流程的能力。 使用容器可以将开发人员的注意力从管理基础结构转移到应用程序开发上。

必备条件

创建异常检测器资源

  1. 登录 Azure 门户

  2. 选择创建异常检测器 资源。

  3. 输入所有必需的设置:

    设置
    名称 所需名称(2-64 个字符)
    订阅 选择相应的订阅
    位置 选择附近任何可用的位置
    定价层 F0 - 每秒 10 次调用,每月 20,000 个事务。
    或:
    S0 - 每秒 80 次调用
    资源组 选择可用的资源组
  4. 选择“创建”并等待创建资源。 创建资源后,导航到“资源”页

  5. 收集配置的 endpoint 和 API 密钥:

    门户中的“密钥和终结点”选项卡 设置 “值”
    概述 端点 复制终结点。 它看起来类似于 https://<your-resource-name>.cognitiveservices.azure.cn/
    “键” API 密钥 复制两个密钥中的 1 个。 它是一个由 32 个字母数字组成的字符串(不包含空格或短划线),即 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

在 Azure CLI 中创建 Azure 容器实例资源

下面的 YAML 定义Azure 容器实例资源。 将内容复制并粘贴到名为 my-aci.yaml 的新文件中,并将注释的值替换为自己的值。 请参阅模板格式以获取有效的 YAML。 请参阅容器存储库和映像,获取可用的映像名称及其相应的存储库。 有关容器实例的 YAML 引用的详细信息,请参阅 YAML 参考:Azure 容器实例

apiVersion: 2018-10-01
location: # < Valid location >
name: # < Container Group name >
properties:
  imageRegistryCredentials: # This is only required if you are pulling a non-public image that requires authentication to access. For example Text Analytics for health.
  - server: containerpreview.azurecr.io
    username: # < The username for the preview container registry >
    password: # < The password for the preview container registry >
  containers:
  - name: # < Container name >
    properties:
      image: # < Repository/Image name >
      environmentVariables: # These env vars are required
        - name: eula
          value: accept
        - name: billing
          value: # < Service specific Endpoint URL >
        - name: apikey
          value: # < Service specific API key >
      resources:
        requests:
          cpu: 4 # Always refer to recommended minimal resources
          memoryInGb: 8 # Always refer to recommended minimal resources
      ports:
        - port: 5000
  osType: Linux
  volumes: # This node, is only required for container instances that pull their model in at runtime, such as LUIS.
  - name: aci-file-share
    azureFile:
      shareName: # < File share name >
      storageAccountName: # < Storage account name>
      storageAccountKey: # < Storage account key >
  restartPolicy: OnFailure
  ipAddress:
    type: Public
    ports:
    - protocol: tcp
      port: 5000
tags: null
type: Microsoft.ContainerInstance/containerGroups

注意

并非所有位置都具有相同的 CPU 和内存可用性。 请参阅位置和资源表,以获取每个位置和 OS 的容器的可用资源列表。

我们将依赖于我们为 az container create 命令创建的 YAML 文件。 在 Azure CLI 中执行 az container create 命令,将 <resource-group> 替换为你自己的值。 另外,若要在 YAML 部署中保护值,请参考安全值

az container create -g <resource-group> -f my-aci.yaml

如果命令有效,则命令的输出为 Running...。过一段时间后,输出更改为表示新建 ACI 资源的 JSON 字符串。 容器映像很可能会在一段时间内不可用,但现在已部署资源。

提示

请密切注意公共预览版 Azure AI 服务的位置,因为需要根据位置来相应地调整 YAML。

验证容器是否正在运行

有几种方法可用于验证容器是否正在运行。 找到相关容器的外部 IP 地址和公开端口,并打开你常用的 Web 浏览器。 使用以下各种请求 URL 验证容器是否正在运行。 此处列出的示例请求 URL 是 http://localhost:5000,但是你的特定容器可能会有所不同。 请确保依赖容器的外部 IP 地址和公开端口。

请求 URL 用途
http://localhost:5000/ 容器提供主页。
http://localhost:5000/ready 使用 GET 对此 URL 进行请求,可以验证容器是否已准备好接受针对模型的查询。 此请求可用于 Kubernetes 运行情况和就绪情况探测
http://localhost:5000/status 同样使用 GET 对此 URL 进行请求,可以验证用于启动容器的 api-key 是否有效,而不会导致终结点查询。 此请求可用于 Kubernetes 运行情况和就绪情况探测
http://localhost:5000/swagger 容器为终结点提供一组完整的文档以及“尝试”功能。 使用此功能可以将设置输入到基于 Web 的 HTML 表单并进行查询,而无需编写任何代码。 查询返回后,将提供示例 CURL 命令,用于演示所需的 HTTP 标头和正文格式。

Container's home page

后续步骤