|
| 1 | +--- |
| 2 | +title: Create an Azure Compute Fleet using Azure CLI |
| 3 | +description: Learn how to create an Azure Compute Fleet using Azure CLI. |
| 4 | +author: ykh015 |
| 5 | +ms.author: yakhande |
| 6 | +ms.topic: how-to |
| 7 | +ms.service: azure-compute-fleet |
| 8 | +ms.date: 05/09/2025 |
| 9 | +ms.reviewer: jushiman |
| 10 | +ms.custom: devx-track-azurecli |
| 11 | +--- |
| 12 | + |
| 13 | +# Create an Azure Compute Fleet using Azure CLI |
| 14 | + |
| 15 | +This article steps through using the Azure CLI to create and deploy a Compute Fleet resource |
| 16 | + |
| 17 | +Make sure that you've installed the latest [Azure CLI](/cli/azure/install-az-cli2) and are logged in to an Azure account with [az login](/cli/azure/reference-index). |
| 18 | + |
| 19 | +## Launch Azure Cloud Shell |
| 20 | + |
| 21 | +The Azure Cloud Shell is a free interactive shell that you can use to run the steps in this article. It has common Azure tools preinstalled and configured to use with your account. |
| 22 | + |
| 23 | +To open the Cloud Shell, select **Open Cloud Shell** from the upper right corner of a code block. You can also launch Cloud Shell in a separate browser tab by going to [https://shell.azure.com/cli](https://shell.azure.com/cli). Select **Copy** to copy the blocks of code, paste it into the Cloud Shell, and press enter to run it. |
| 24 | + |
| 25 | +## Prerequisites |
| 26 | + |
| 27 | +- If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin. |
| 28 | +- Before using Compute Fleet, complete the feature registration and configure role-based access controls (RBAC). |
| 29 | + |
| 30 | +## Feature registration |
| 31 | + |
| 32 | +Register the Azure Compute Fleet resource provider with your subscription using Azure CLI. Registration can take up to 30 minutes to successfully show as registered. |
| 33 | + |
| 34 | +```azurecli-interactive |
| 35 | +az provider register --namespace 'Microsoft.AzureFleet' |
| 36 | +``` |
| 37 | + |
| 38 | +## Define environment variables |
| 39 | + |
| 40 | +Define environment variables as follows. |
| 41 | + |
| 42 | +```bash |
| 43 | +export RANDOM_ID="$(openssl rand -hex 3)" |
| 44 | +export MY_RESOURCE_GROUP_NAME="myFleetResourceGroup$RANDOM_ID" |
| 45 | +export REGION=EastUS |
| 46 | +export MY_FLEET_NAME="myFleet$RANDOM_ID" |
| 47 | +export MY_USERNAME=azureuser |
| 48 | +export MY_VNET_NAME="myVNet$RANDOM_ID" |
| 49 | +export NETWORK_PREFIX="$(($RANDOM % 254 + 1))" |
| 50 | +export MY_VNET_PREFIX="10.$NETWORK_PREFIX.0.0/16" |
| 51 | +export MY_VM_SN_NAME="myVMSN$RANDOM_ID" |
| 52 | +export MY_VM_SN_PREFIX="10.$NETWORK_PREFIX.0.0/24" |
| 53 | +``` |
| 54 | + |
| 55 | +## Create a resource group |
| 56 | + |
| 57 | +A resource group is a logical container into which Azure resources are deployed and managed. All resources must be placed in a resource group. The following command creates a resource group with the previously defined `$MY_RESOURCE_GROUP_NAME` and `$REGION` parameters. |
| 58 | + |
| 59 | +```azurecli-interactive |
| 60 | +az group create --name $MY_RESOURCE_GROUP_NAME --location $REGION |
| 61 | +``` |
| 62 | + |
| 63 | +## Create virtual network and subnet |
| 64 | + |
| 65 | +Now you'll create a virtual network using the previously defined `$MY_VNET_PREFIX`, `$MY_VM_SN_NAME`, and `$MY_VM_SN_PREFIX` parameters. |
| 66 | + |
| 67 | +```azurecli-interactive |
| 68 | +az network vnet create --name $MY_VNET_NAME --resource-group $MY_RESOURCE_GROUP_NAME --location $REGION --address-prefix $MY_VNET_PREFIX --subnet-name $MY_VM_SN_NAME --subnet-prefix $MY_VM_SN_PREFIX |
| 69 | +``` |
| 70 | + |
| 71 | +The following command gets the subnet ARM ID. |
| 72 | + |
| 73 | +```azurecli-interactive |
| 74 | +export MY_SUBNET_ID="$(az network vnet subnet show \ |
| 75 | + --resource-group $MY_RESOURCE_GROUP_NAME \ |
| 76 | + --vnet-name $MY_VNET_NAME \ |
| 77 | + --name $MY_VM_SN_NAME \ |
| 78 | + --query id --output tsv)" |
| 79 | +``` |
| 80 | + |
| 81 | +## Set up the admin password |
| 82 | + |
| 83 | +Set up a password that meets the [password requirements for Azure VMs](https://learn.microsoft.com/azure/virtual-machines/windows/faq#what-are-the-password-requirements-when-creating-a-vm-). |
| 84 | + |
| 85 | +```bash |
| 86 | +export ADMIN_PASSWORD="Azure compliant password" |
| 87 | +``` |
| 88 | + |
| 89 | +## Create a Compute Fleet |
| 90 | + |
| 91 | +Set up the compute profile which is applied to the underlying VMs. |
| 92 | + |
| 93 | +```bash |
| 94 | +export COMPUTE_PROFILE="{ 'baseVirtualMachineProfile': { 'storageProfile': { 'imageReference': { 'publisher':'canonical', 'offer':'0001-com-ubuntu-server-focal', 'sku': '20_04-lts-gen2', 'version': 'latest' } }, 'osProfile': { 'computerNamePrefix': 'vm', 'adminUsername': '$MY_USERNAME', 'adminPassword': '$ADMIN_PASSWORD'}, 'networkProfile': { 'networkInterfaceConfigurations': [{ 'name': 'nic', 'primary': 'true', 'enableIPForwarding': 'true', 'ipConfigurations': [{ 'name': 'ipc', 'subnet': { 'id': '$MY_SUBNET_ID' } }] }], 'networkApiVersion': '2020-11-01'} } }" |
| 95 | +``` |
| 96 | + |
| 97 | +```azurecli-interactive |
| 98 | +az compute-fleet create --name $MY_FLEET_NAME --resource-group $MY_RESOURCE_GROUP_NAME --location $REGION \ |
| 99 | + --spot-priority-profile "{ 'capacity': 5 }" \ |
| 100 | + --regular-priority-profile "{ 'capacity': 5 }" \ |
| 101 | + --compute-profile "$COMPUTE_PROFILE" \ |
| 102 | + --vm-sizes-profile "[{ 'name': 'Standard_F1s' }]" |
| 103 | +``` |
| 104 | + |
| 105 | +## Clean up resources (optional) |
| 106 | + |
| 107 | +To avoid Azure charges, you should clean up unneeded resources. When you no longer need your Compute Fleet and other resources, delete the resource group and all its resources with [az group delete](/cli/azure/group). The `--no-wait` parameter returns control to the prompt without waiting for the operation to complete. The `--yes` parameter confirms that you wish to delete the resources without another prompt to do so. |
| 108 | + |
| 109 | +## Next steps |
| 110 | +> [!div class="nextstepaction"] |
| 111 | +> [Learn how to modify a Compute Fleet.](modify-fleet.md) |
0 commit comments