YAML 参考:Azure 容器实例

本文介绍 Azure 容器实例支持的、用于配置容器组的 YAML 文件的语法和属性。 使用 YAML 文件可将组配置输入到 Azure CLI 中的 az container create 命令。

YAML 文件是为可再现的部署配置容器组的便捷方式。 它可以取代资源管理器模板或 Azure 容器实例 SDK,以简洁的方式创建或更新容器组。

注意

本参考文章适用于 Azure 容器实例 REST API 版本 2021-10-01 的 YAML 文件。

架构

下面是 YAML 文件的架构,其中的注释突出显示了关键属性。 有关此架构中的属性的说明,请参阅属性值部分。

name: string  # Name of the container group
apiVersion: '2021-10-01'
location: string
tags: {}
identity: 
  type: string
  userAssignedIdentities: {}
properties: # Properties of container group
  containers: # Array of container instances in the group
  - name: string # Name of an instance
    properties: # Properties of an instance
      image: string # Container image used to create the instance
      command:
      - string
      ports: # External-facing ports exposed on the instance, must also be set in group ipAddress property 
      - protocol: string
        port: integer
      environmentVariables:
      - name: string
        value: string
        secureValue: string
      resources: # Resource requirements of the instance
        requests:
          memoryInGB: number
          cpu: number
          gpu:
            count: integer
            sku: string
        limits:
          memoryInGB: number
          cpu: number
          gpu:
            count: integer
            sku: string
      volumeMounts: # Array of volume mounts for the instance
      - name: string
        mountPath: string
        readOnly: boolean
      livenessProbe:
        exec:
          command:
          - string
        httpGet:
          httpHeaders:
          - name: string
            value: string
          path: string
          port: integer
          scheme: string
        initialDelaySeconds: integer
        periodSeconds: integer
        failureThreshold: integer
        successThreshold: integer
        timeoutSeconds: integer
      readinessProbe:
        exec:
          command:
          - string
        httpGet:
          httpHeaders:
          - name: string
            value: string
          path: string
          port: integer
          scheme: string
        initialDelaySeconds: integer
        periodSeconds: integer
        failureThreshold: integer
        successThreshold: integer
        timeoutSeconds: integer
  imageRegistryCredentials: # Credentials to pull a private image
  - server: string
    username: string
    password: string
    identity: string
    identityUrl: string
  restartPolicy: string
  ipAddress: # IP address configuration of container group
    ports:
    - protocol: string
      port: integer
    type: string
    ip: string
    dnsNameLabel: string
    autoGeneratedDomainNameLabelScope: string
  osType: string
  volumes: # Array of volumes available to the instances
  - name: string
    azureFile:
      shareName: string
      readOnly: boolean
      storageAccountName: string
      storageAccountKey: string
    emptyDir: {}
    secret: {}
    gitRepo:
      directory: string
      repository: string
      revision: string
  diagnostics:
    logAnalytics:
      workspaceId: string
      workspaceKey: string
      workspaceResourceId: string
      logType: string
      metadata: {}
  subnetIds: # Subnet to deploy the container group into
    - id: string
      name: string
  dnsConfig: # DNS configuration for container group
    nameServers:
    - string
    searchDomains: string
    options: string
  sku: string # SKU for the container group
  encryptionProperties:
    vaultBaseUrl: string
    keyName: string
    keyVersion: string
  initContainers: # Array of init containers in the group
  - name: string
    properties:
      image: string
      command:
      - string
      environmentVariables:
      - name: string
        value: string
        secureValue: string
      volumeMounts:
      - name: string
        mountPath: string
        readOnly: boolean

属性值

下表描述了需要在架构中设置的值。

Microsoft.ContainerInstance/containerGroups 对象

名称 类型 必选 价值
name 字符串 容器组的名称。
apiVersion 枚举 2021-10-01(最新)、2021-09-01、2021-07-01、2021-03-01、2020-11-01、2019-12-01、2018-10-01、2018-09-01、2018-07-01、2018-06-01、2018-04-01
位置 字符串 资源位置。
tags 对象 资源标记。
标识 对象 容器组的标识(如果已配置)。 - ContainerGroupIdentity 对象
properties 对象 ContainerGroupProperties 对象

ContainerGroupIdentity 对象

名称 类型 必选 价值
类型 枚举 容器组使用的标识类型。 类型“SystemAssigned ,UserAssigned”包含隐式创建的标识和一组用户分配的标识。 类型“None”会移除容器组中的所有标识。 - SystemAssigned、UserAssigned、SystemAssigned、UserAssigned、None
userAssignedIdentities 对象 与容器组关联的用户标识列表。 用户标识字典键引用是采用以下格式的 Azure 资源管理器资源 ID:“/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}”。

ContainerGroupProperties 对象

名称 类型 必选 价值
containers 数组 容器组中的容器。 - Container 对象
imageRegistryCredentials 数组 创建容器组所依据的映像注册表凭据。 - ImageRegistryCredential 对象
restartPolicy 枚举 容器组中所有容器的重启策略。 - Always 始终重启-OnFailure 失败时重启- Never 永不重启。 - Always、OnFailure、Never
ipAddress 对象 容器组的 IP 地址类型。 - IpAddress 对象
osType 枚举 容器组中容器所需的操作系统类型。 - Windows 或 Linux
volumes 数组 此容器组中的容器可以装载的卷列表。 - Volume 对象
诊断 对象 容器组的诊断信息。 - ContainerGroupDiagnostics 对象
subnetId 对象 容器组的子网信息。 - ContainerGroupSubnetIds 对象
dnsConfig 对象 容器组的 DNS 配置信息。 - DnsConfiguration 对象
sku 枚举 容器组的 SKU - 标准或专用
encryptionProperties 对象 容器组的加密属性。 - EncryptionProperties 对象
initContainers 数组 容器组的 Init 容器。 - InitContainerDefinition 对象

Container 对象

名称 类型 必选 价值
name 字符串 用户提供的容器实例名称。
properties 对象 容器实例的属性。 - ContainerProperties 对象

ImageRegistryCredential 对象

名称 类型 必选 价值
服务器 字符串 没有协议(例如“http”或“https”)的 Docker 映像注册表服务器。
用户名 字符串 专用注册表的用户名。
密码 字符串 专用注册表的密码。
标识 字符串 用于进行身份验证的用户分配托管标识的资源 ID。 ACR 映像拉取不支持系统分配的托管标识。
identityUrl 字符串 专用注册表的标识 URL。

IpAddress 对象

名称 类型 必选 价值
ports 数组 容器组上公开的端口列表。 - Port 对象
类型 枚举 指定 IP 是否向公共 Internet 或专用虚拟网络公开。 - Public 或 Private
ip 字符串 向公共 Internet 公开的 IP。
dnsNameLabel 字符串 IP 的 DNS 名称标签。

Volume 对象

名称 类型 必选 价值
name 字符串 卷的名称。
azureFile 对象 Azure 文件卷。 - AzureFileVolume 对象
emptyDir 对象 空目录卷。
机密 对象 机密卷。
gitRepo 对象 Git 存储库卷。 - GitRepoVolume 对象

ContainerGroupDiagnostics 对象

名称 类型 必选 价值
logAnalytics 对象 容器组日志分析信息。 - LogAnalytics 对象

ContainerGroupSubnetIds 对象

名称 类型 必选 价值
id 字符串 子网的标识符。
name 字符串 子网的名称。

DnsConfiguration 对象

名称 类型 必选 价值
nameServers 数组 容器组的 DNS 服务器。 -字符串
searchDomains 字符串 容器组中主机名查找的 DNS 搜索域。
options 字符串 容器组的 DNS 选项。

EncryptionProperties 对象

名称 类型 必选 价值
vaultBaseUrl 字符串 密钥保管库基础 URL。
keyName 字符串 加密密钥名称。
keyVersion 字符串 加密密钥版本。

InitContainerDefinition 对象

名称 类型 必选 价值
name 字符串 Init 容器的名称。
properties 对象 Init 容器的属性。 - InitContainerPropertiesDefinition 对象

ContainerProperties 对象

名称 类型 必选 价值
图像 字符串 用于创建容器实例的映像的名称。
command 数组 要在容器实例中执行的 exec 形式的命令。 -字符串
ports 数组 容器实例上的已公开端口。 - ContainerPort 对象
environmentVariables 数组 要在容器实例中设置的环境变量。 - EnvironmentVariable 对象
resources 对象 容器实例的资源要求。 - ResourceRequirements 对象
volumeMounts 数组 容器实例可用的卷装入点数。 - VolumeMount 对象
livenessProbe 对象 运行情况探测。 - ContainerProbe 对象
readinessProbe 对象 就绪情况探测。 - ContainerProbe 对象

Port 对象

名称 类型 必选 价值
协议 枚举 与端口关联的协议。 - TCP 或 UDP
移植 整数 端口号。

AzureFileVolume 对象

名称 类型 必选 价值
shareName 字符串 要以卷形式装载的 Azure 文件共享的名称。
readOnly boolean 指示以卷形式装载的 Azure 文件共享是否为只读的标志。
storageAccountName 字符串 包含 Azure 文件共享的存储帐户的名称。
storageAccountKey 字符串 用于访问 Azure 文件共享的存储帐户访问密钥。

GitRepoVolume 对象

名称 类型 必选 价值
目录 字符串 目标目录名称。 不得包含“..”,也不能以其开头。 如果提供了“.”,则卷目录是 Git 存储库。 否则,卷包含子目录中具有给定名称的 Git 存储库(如果已指定)。
仓库 字符串 存储库 URL
revision 字符串 指定的修订版的提交哈希。

LogAnalytics 对象

名称 类型 必选 价值
workspaceId 字符串 Log Analytics 的工作区 ID
workspaceKey 字符串 Log Analytics 的工作区键
workspaceResourceId 字符串 Log Analytics 的工作区资源 ID
logType 枚举 要使用的日志类型。 - ContainerInsights 或 ContainerInstanceLogs
元数据 对象 Log Analytics 的元数据。

InitContainerPropertiesDefinition 对象

名称 类型 必选 价值
图像 字符串 Init 容器的映像。
command 数组 要在 Init 容器中以 exec 形式执行的命令。 -字符串
environmentVariables 数组 要在 Init 容器中设置的环境变量。 - EnvironmentVariable 对象
volumeMounts 数组 可用于 Init 容器的卷装载。 - VolumeMount 对象

ContainerPort 对象

名称 类型 必选 价值
协议 枚举 与端口关联的协议。 - TCP 或 UDP
移植 整数 容器组中公开的端口号。

EnvironmentVariable 对象

名称 类型 必选 价值
name 字符串 环境变量的名称。
value 字符串 环境变量的值。
secureValue 字符串 安全环境变量的值。

ResourceRequirements 对象

名称 类型 必选 价值
请求 对象 此容器实例的资源请求。 - ResourceRequests 对象
限制 对象 此容器实例的资源限制。 - ResourceLimits 对象

VolumeMount 对象

名称 类型 必选 价值
name 字符串 卷装入点的名称。
mountPath 字符串 容器中要将该卷装载到的路径。 不得包含冒号 (:)。
readOnly boolean 指示卷装入点是否为只读的标志。

ContainerProbe 对象

名称 类型 必选 价值
exec 对象 用于探测的执行命令 - ContainerExec 对象
httpGet 对象 用于探测的 Http Get 设置 - ContainerHttpGet 对象
initialDelaySeconds 整数 初始延迟秒数。
periodSeconds 整数 时间段秒数。
failureThreshold 整数 失败阈值。
successThreshold 整数 成功阈值。
timeoutSeconds 整数 超时秒数。

ResourceRequests 对象

名称 类型 必选 价值
memoryInGB number 此容器实例的内存请求 (GB)。
cpu number 此容器实例的 CPU 请求。
gpu 对象 此容器实例的 GPU 请求。 - GpuResource 对象

ResourceLimits 对象

名称 类型 必选 价值
memoryInGB number 此容器实例的内存限制 (GB)。
cpu number 此容器实例的 CPU 限制。
gpu 对象 此容器实例的 GPU 限制。 - GpuResource 对象

ContainerExec 对象

名称 类型 必选 价值
command 数组 要在容器中执行的命令。 -字符串

ContainerHttpGet 对象

名称 类型 必选 价值
路径 字符串 要探测的路径。
移植 整数 要探测的端口号。
scheme 枚举 方案。 - http 或 https
httpHeaders 对象 探测中包含的 HTTP 标头。 - HttpHeaders 对象

HttpHeaders 对象

名称 类型 必选 价值
name 字符串 标头名称。
value 字符串 标头的值。

重要

K80 和 P100 GPU SKU 将于 2023 年 8 月 31 日停用。 这是因为使用的基础 VM 将停用:NC 系列和 NCv2 系列 尽管 V100 SKU 将可用,但建议改用使用 Azure Kubernetes 服务。 GPU 资源不完全受支持,不应用于生产工作负荷。 立即使用以下资源迁移到 AKS:如何迁移到 AKS

GpuResource 对象

名称 类型 必选 价值
count 整数 GPU 资源计数。
sku 枚举 GPU 资源的 SKU。 - V100

后续步骤

参阅教程使用 YAML 文件部署多容器组

参阅使用 YAML 文件在虚拟网络中部署容器组或装载外部卷的示例。