需要帮助重新映像具有虚拟机配置的Azure批处理池中的现有Azure节点

问题描述 投票:1回答:1

有没有人有关如何重新映像我的Azure批处理池帐户中的Linux节点而不调整为0然后返回N,或删除池并再次创建它的建议?

或者这是推荐的最佳做法

更多细节:

我在重新成像天蓝色节点时遇到问题。当我更新docker镜像并使用ARM模板重新部署时,节点不会提取最新的docker镜像。我想这可能是因为图像名称是相同的(我总是想要最新的图像)

我尝试过使用:

重置-AceanBatchComputeNode,但在fiddler上给出了以下错误“只能在使用cloudServiceConfiguration创建的池上调用操作重新映像”。我无法使用云服务配置,因为该机器需要是Linux机器。

Restart-AzureBatchComputeNode,但只重新启动节点而不是重新映像

我可能只需要核对节点(调整大小为0,然后再按我需要的数量旋转),或者只是删除池然后再次设置它。但这些似乎是“核”选项,批量服务将会停止,直到节点再次被旋转。

我用来部署/更新批处理池的arm模板

{
      "name": "[concat(parameters('batchAccountName'), '/<pool-name>')]",
      "type": "Microsoft.Batch/batchAccounts/pools",
      "apiVersion": "2018-12-01",
      "properties": {
        "vmSize": "[parameters('vmSize')]",
        "deploymentConfiguration": {
          "virtualMachineConfiguration": {
            "nodeAgentSkuId": "batch.node.ubuntu 16.04",
            "imageReference": {
              "publisher": "microsoft-azure-batch",
              "offer": "ubuntu-server-container",
              "sku": "16-04-lts",
              "version": "latest"
            },
            "containerConfiguration": {
              "type": "DockerCompatible",
              "containerImageNames": [
                "[concat(parameters('containerRegistryServer'), '/<container-name>')]"
              ],
              "containerRegistries": [
                <credentials>
              ]
            }
          }
        },
        "scaleSettings": {
          "fixedScale": {
            "targetDedicatedNodes": "[parameters('targetDedicatedNodes')]"
          }
        }
      },
      "dependsOn": [
        "[resourceId('Microsoft.Batch/batchAccounts', parameters('batchAccountName'))]"
      ]
    },

--

更新:

谢谢@fpark,根据你的建议,我提出了以下powershell脚本,以防其他人

Write-Output "Building docker image"
$imageHashBeforeBuild = docker images $DockerImageName --format "{{.ID}}" --no-trunc
docker build -t $DockerImageName $pathToEnergyModel
if (!$?) {
    throw "Docker image $DockerImageName failed to build"
}
$imageHashAfterBuild = docker images $DockerImageName --format "{{.ID}}" --no-trunc

...

$batchContext = Get-AzureRmBatchAccount -Name $batchAccountName

...

# The nodes should only be reimaged if the model has an update and this is NOT a new deployment
$ShouldReimageNodes = $IsUpdate -and $imageHashBeforeBuild -and ($imageHashBeforeBuild -ne $imageHashAfterBuild)
# The batchAccountDeployment step will create/update batch accounts/pools, 
# However, the deployment does not update the VM image to the latest present in the docker container registry
# This is likely due to the ARM template having the same settings, so it doesn't know to try pull the image down again
# As a work around:
#   1) Grab all current nodes
#   2) For each node:
#       a) Bring it down (this has a side effect of reducing TargetDedicatedComputeNodes by 1)
#       b) Resize the number of TargetDedicatedComputeNodes to correct value (i.e. spin up a node to replace the one downed in 2a)
# When the VM's come back up, they indeed pull the latest docker image
if ($ShouldReimageNodes) {
    # Wait for nodes to stabilize
    Write-Host "Difference in docker images detected. Restarting each node one at a time to ensure latest docker image is being used."
    while ((Get-AzureBatchPool -BatchContext $batchContext -Id $PoolName).AllocationState -ne "Steady") {
        Write-Host "Waiting for nodes in $PoolName to stabilize. Checking status again in $SleepTime seconds."
        Start-Sleep -Seconds $SleepTime
    }
    $nodes = Get-AzureBatchComputeNode -PoolId $PoolName -BatchContext $batchContext
    $currentNodeCount = $nodes.Length
    foreach ($node in $nodes) {
        $nodeId = $node.Id
        Write-Host "Removing node $nodeId"
        Remove-AzureBatchComputeNode -ComputeNode $node -BatchContext $batchContext -Force
        while ((Get-AzureBatchPool -BatchContext $batchContext -Id $PoolName).AllocationState -ne "Steady") {
            Write-Host "Waiting for nodes in $PoolName to stabilize. Checking status again in $SleepTime seconds."
            Start-Sleep -Seconds $SleepTime
        }
        Write-Host "Resizing back to $currentNodeCount"
        Start-AzureBatchPoolResize -Id $PoolName -BatchContext $batchContext -TargetDedicatedComputeNodes $currentNodeCount
        while ((Get-AzureBatchPool -BatchContext $batchContext -Id $PoolName).AllocationState -ne "Steady") {
            Write-Host "Waiting for nodes in $PoolName to stabilize. Checking status again in $SleepTime seconds."
            Start-Sleep -Seconds $SleepTime
        }
    }
}
docker azure-virtual-machine continuous-deployment azure-resource-manager azure-batch
1个回答
1
投票

目前,不支持基于虚拟机配置的池上的重新映像操作。请参阅this uservoice idea

您可以通过调用Remove-AzureBatchComputeNode cmdlet来模拟重新映像一组节点,然后调整大小以恢复所需的大小。

© www.soinside.com 2019 - 2024. All rights reserved.