簡體   English   中英

Azure 批處理 NodePreparationError 試圖從 Azure Container Registry 獲取 Docker 圖像

[英]Azure Batch NodePreparationError trying to fetch Docker image from Azure Container Registry

我正在嘗試在 Ubuntu VM 上運行 Azure 批處理任務,並使用從私有 Azure 容器注冊表中提取的圖像。 池中的節點創建失敗並出現以下錯誤,無論我是否預取:

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 Quickstart 示例Batch 文檔

我已經嘗試了Troubleshoot registry login guide 中的各種步驟但沒有效果。 我通過 Azure Shell 登錄 ACR 沒有問題,但這是我的普通用戶,當然不是 UAMI。

已更改 GUID 以保護無辜者。

哈爾普?

為池使用托管標識時,您必須將標識添加到池本身,在帳戶上設置標識允許批處理服務本身使用標識,但不能使用池中的 VM。 請注意,您實際上不需要在您的用例(Azure 容器注冊表)中設置帳戶身份,只需設置池即可。

請在此處查看有關將身份分配給池的文檔:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM