-1

我正在尝试使用从私有 Azure 容器注册表中提取的图像在 Ubuntu VM 上运行 Azure Batch 任务。池中的节点在创建时失败并出现以下错误,无论我是否预取:

Code: NodePreparationError

Message:
An error occurred during node preparation

Values:
Error - Hit unexpected error installing containers
Message - 400, message='Bad Request', url=URL('http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://management.azure.com/&mi_res_id=/subscriptions/7bd2fd6e-1cb6-4db2-82fe-67c7ea3024cd/resourceGroups/SANDBOX/providers/Microsoft.ManagedIdentity/userAssignedIdentities/my_uami')

基线:我有一个包含资源组的 Azure 订阅。在资源组中是

  • 容器注册表,
  • 批量帐户,以及
  • 用户分配的托管身份。

UAMI 在 Container Registry 和 Batch Account 的身份刀片中分配。AcrPull管理员已为我的订阅分配了该角色。

我可以将图像拉到我的本地机器上,所以我知道它存在。我尝试在从 Docker Hub 预取的python3.7-slim图像上运行一个简单的任务并成功,所以问题出在 Batch 和 ACR 之间。

这是一个演示问题的最小示例:

from azure.batch import BatchServiceClient
from azure.batch.batch_auth import SharedKeyCredentials
from azure.batch.models import (
  ComputeNodeIdentityReference,
  ContainerConfiguration,
  ContainerRegistry,
  ImageReference,
  JobAddParameter,
  PoolAddParameter,
  PoolInformation,
  VirtualMachineConfiguration,
)

if __name__ == '__main__':
  batch_service_client = BatchServiceClient(
    SharedKeyCredentials('batchtest2021', 'GZTn…………………………………pGJ+gNE…………………………dvw=='),
    batch_url='https://batchtest2021.westeurope.batch.azure.com/',
  )
  pool_id = 'my_test_pool'
  new_pool = PoolAddParameter(
    id=pool_id,
    virtual_machine_configuration=VirtualMachineConfiguration(
      container_configuration=ContainerConfiguration(
        container_image_names=[
          'myprivateacr.azurecr.io/mydockerimage:latest',
        ],
        container_registries=[
          ContainerRegistry(
            registry_server='myprivateacr.azurecr.io',
            identity_reference=ComputeNodeIdentityReference(
              resource_id=f'/subscriptions/7bd2fd6e-1cb6-4db2-82fe-67c7ea3024cd/resourceGroups/SANDBOX/providers/Microsoft.ManagedIdentity/userAssignedIdentities/my_uami'
            ),
          ),
        ],
      ),
      image_reference=ImageReference(
        publisher='microsoft-azure-batch',
        offer='ubuntu-server-container',
        sku='20-04-lts',
        version='latest',
      ),
      node_agent_sku_id='batch.node.ubuntu 20.04',
    ),
    vm_size='STANDARD_A2M_V2',
    target_dedicated_nodes=2,
  )
  batch_service_client.pool.add(new_pool)

  job = JobAddParameter(id='sample_job_id', pool_info=PoolInformation(pool_id=pool_id))
  batch_service_client.job.add(job)

该代码基于Batch Python 快速入门示例Batch 文档

我尝试了注册表登录疑难解答指南中的各种步骤,但均无效。我通过 Azure Shell 登录 ACR 没有问题,但那是我的普通用户,当然不是 UAMI。

GUID 已更改以保护无辜者。

哈普?

4

1 回答 1

2

将托管标识用于池时,您必须将标识添加到池本身,在帐户上设置标识允许批处理服务本身使用标识,但不能使用池中的 VM。请注意,您实际上不需要在用例(Azure 容器注册表)中的帐户上设置标识,只需在池中设置。

请在此处查看有关将身份分配给池的文档:

https://docs.microsoft.com/azure/batch/managed-identity-pools

于 2021-09-28T13:51:51.493 回答