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

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
    dnsNameLabelReusePolicy: 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
location 字符串 资源位置。
tags object 资源标记。
identity object 容器组的标识(如果已配置)。 - ContainerGroupIdentity 对象
properties object ContainerGroupProperties 对象

ContainerGroupIdentity 对象

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

ContainerGroupProperties 对象

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

Container 对象

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

ImageRegistryCredential 对象

名称 类型 必须 Value
server string 没有协议(例如“http”或“https”)的 Docker 映像注册表服务器。
username string 专用注册表的用户名。
password string 专用注册表的密码。
标识 字符串 用于进行身份验证的用户或系统分配的托管标识的资源 ID。
identityUrl 字符串 专用注册表的标识 URL。

IpAddress 对象

名称 类型 必须 Value
ports array 容器组上公开的端口列表。 - Port 对象
type 枚举 指定 IP 是否向公共 Internet 或专用 VNET 公开。 - Public 或 Private
ip string 向公共 Internet 公开的 IP。
dnsNameLabel string IP 的 DNS 名称标签。

Volume 对象

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

ContainerGroupDiagnostics 对象

名称 类型 必须 Value
logAnalytics object 容器组日志分析信息。 - LogAnalytics 对象

ContainerGroupSubnetIds 对象

名称 类型 必须 Value
id 字符串 子网的标识符。
name 字符串 子网的名称。

DnsConfiguration 对象

名称 类型 必须 Value
nameServers array 容器组的 DNS 服务器。 - string
searchDomains string 容器组中主机名查找的 DNS 搜索域。
options string 容器组的 DNS 选项。

EncryptionProperties 对象

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

InitContainerDefinition 对象

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

ContainerProperties 对象

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

Port 对象

名称 类型 必须 Value
协议 枚举 与端口关联的协议。 - TCP 或 UDP
port integer 端口号。

AzureFileVolume 对象

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

GitRepoVolume 对象

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

LogAnalytics 对象

名称 类型 必须 Value
workspaceId string Log Analytics 的工作区 ID
workspaceKey string Log Analytics 的工作区键
workspaceResourceId 字符串 Log Analytics 的工作区资源 ID
logType 枚举 要使用的日志类型。 - ContainerInsights 或 ContainerInstanceLogs
metadata object Log Analytics 的元数据。

InitContainerPropertiesDefinition 对象

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

ContainerPort 对象

名称 类型 必须 Value
协议 枚举 与端口关联的协议。 - TCP 或 UDP
port integer 容器组中公开的端口号。

EnvironmentVariable 对象

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

ResourceRequirements 对象

名称 类型 必须 Value
请求 object 此容器实例的资源请求。 - ResourceRequests 对象
限制 object 此容器实例的资源限制。 - ResourceLimits 对象

VolumeMount 对象

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

ContainerProbe 对象

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

ResourceRequests 对象

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

ResourceLimits 对象

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

ContainerExec 对象

名称 类型 必须 Value
command array 要在容器中执行的命令。 - string

ContainerHttpGet 对象

名称 类型 必须 Value
path string 要探测的路径。
port integer 要探测的端口号。
scheme 枚举 方案。 - http 或 https
httpHeaders object 探测中包含的 HTTP 标头。 - HttpHeaders 对象

HttpHeaders 对象

名称 类型 必须
name 字符串 标头名称。
字符串 标头的值。

重要

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

GpuResource 对象

名称 类型 必须 Value
count integer GPU 资源计数。
sku 枚举 GPU 资源的 SKU。 - V100

后续步骤

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

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