MSDN Docs Search

Manage Pools in Azure Batch

This tutorial walks you through the steps to create, update, scale, and delete pools in Azure Batch using the Azure CLI and .NET SDK.

Prerequisites

1. Create a Pool with Azure CLI

Run the following command to create a pool named myPool with 3 Standard_D2_v2 VMs.

az batch pool create \
    --resource-group MyResourceGroup \
    --account-name MyBatchAccount \
    --id myPool \
    --vm-size Standard_D2_v2 \
    --target-dedicated-nodes 3 \
    --image canonical:UbuntuServer:18.04-LTS:latest \
    --node-agent-sku-id batch.node.ubuntu 18.04

2. Scale the Pool Programmatically (C#)

Use the Azure Batch .NET SDK to increase the pool size to 5 nodes.

using Azure;
using Azure.Identity;
using Azure.ResourceManager.Batch;
using Azure.ResourceManager.Batch.Models;

var credential = new DefaultAzureCredential();
var batchClient = new BatchManagementClient(credential);
var pool = await batchClient.Pool.GetAsync("MyResourceGroup", "MyBatchAccount", "myPool");

var update = new PoolUpdateOptions
{
    TargetDedicated = 5
};

await batchClient.Pool.UpdateAsync("MyResourceGroup", "MyBatchAccount", "myPool", update);
Console.WriteLine("Pool scaled to 5 nodes.");

3. Delete a Pool

When the pool is no longer needed, delete it using Azure CLI:

az batch pool delete \
    --resource-group MyResourceGroup \
    --account-name MyBatchAccount \
    --pool-id myPool \
    --yes

4. Verify Pool State

Check the status of your pool:

az batch pool show \
    --resource-group MyResourceGroup \
    --account-name MyBatchAccount \
    --pool-id myPool

Next Steps