Azure CLI Installing and Utilizing 🚀

jay75chauhan
4 min readAug 29, 2024

--

The Azure Command Line Interface (CLI) is a unified tool that allows you to manage and automate various Azure services using commands in your terminal. It simplifies the process of working with Azure by providing a powerful way to control and script Azure services.

1. Installing Azure CLI

To install Azure CLI on your system:

  • On Linux:
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
  • On macOS:
brew update && brew install azure-cli
  • On Windows: Download the installer from Azure CLI Installer for Windows and follow the installation wizard.
  • Verify Installation:
az --version

2. Configuring Azure CLI

Log in to your Azure account:

az login

This command will open a web browser to complete the authentication process.

  • If using a service principal (for automation):
az login --service-principal -u <app-id> -p <password> --tenant <tenant-id>

3. Common Azure CLI Commands for DevOps Engineers

Here are essential Azure CLI commands for managing various Azure services:

Azure Virtual Machines

  • Create a new VM:
az vm create --resource-group myResourceGroup --name myVM --image UbuntuLTS --admin-username azureuser --generate-ssh-keys
  • List all VMs:
az vm list --output table
  • Stop a VM:
az vm stop --resource-group myResourceGroup --name myVM
  • Start a VM:
az vm start --resource-group myResourceGroup --name myVM
  • Delete a VM:
az vm delete --resource-group myResourceGroup --name myVM --yes --no-wait

Azure Resource Groups

  • Create a new Resource Groups:
az group create --name myResourceGroup --location eastus
  • List Resource Groups:
az group list --output table
  • Delete a Resource Groups:
az group delete --name myResourceGroup --yes --no-wait

Azure Virtual Network

  • Create a new virtual network:
az network vnet create --resource-group myResourceGroup --name myVNet --address-prefix 10.0.0.0/16
  • List virtual networks:
az network vnet list --output table
  • Delete a virtual network:
az network vnet delete --resource-group myResourceGroup --name myVNet

Azure Storage

  • Create a new storage account:
az storage account create --name mystorageaccount --resource-group myResourceGroup --location eastus --sku Standard_LRS
  • List all storage accounts:
az storage account list --output table
  • Upload a file to a blob container:
az storage blob upload --container-name mycontainer --file myfile.txt --name myfile.txt --account-name mystorageaccount
  • List blobs in a container:
az storage blob list --container-name mycontainer --account-name mystorageaccount --output table

Azure Kubernetes Service (AKS)

  • Create an AKS cluster:
az aks create --resource-group myResourceGroup --name myAKSCluster --node-count 1 --enable-addons monitoring --generate-ssh-keys
  • Get the credentials for the AKS cluster:
az aks get-credentials --resource-group myResourceGroup --name myAKSCluste
  • List AKS clusters:
az aks list --output table
  • Delete an AKS cluster:
az aks delete --resource-group myResourceGroup --name myAKSCluster --yes --no-wait

Azure Container Registry (ACR)

  • Create a new ACR:
az acr create --resource-group myResourceGroup --name myACR --sku Basic
  • Login to ACR:
az acr login --name myACR
  • List ACRs:
az acr list --output table
  • Delete an ACR:
az acr delete --resource-group myResourceGroup --name myACR --yes --no-wait

Azure SQL Database

  • Create a new SQL server:
az sql server create --name myServer --resource-group myResourceGroup --location eastus --admin-user myAdmin --admin-password myPassword123
  • Create a new SQL database:
az sql db create --resource-group myResourceGroup --server myServer --name myDatabase --service-objective S0
  • List SQL databases:
az sql db list --resource-group myResourceGroup --server myServer --output table
  • Delete a SQL database:
az sql db delete --resource-group myResourceGroup --server myServer --name myDatabase --yes --no-wait

Azure Functions

  • Create a new Function App:
az functionapp create --resource-group myResourceGroup --consumption-plan-location eastus --name myFunctionApp --storage-account mystorageaccount --runtime node
  • List Function Apps:
az functionapp list --output table
  • Delete a Function App:
az functionapp delete --resource-group myResourceGroup --name myFunctionApp

Azure Resource Manager (ARM) Templates

  • Deploy an ARM template:
az deployment group create --resource-group myResourceGroup --template-file mytemplate.json --parameters myparameters.json
  • List deployments:
az deployment group list --resource-group myResourceGroup --output table

Azure DevOps

  • Create a new Azure DevOps project:
az devops project create --name myProject
  • List Azure DevOps projects:
az devops project list
  • Create a new repository:
az repos create --name myRepo
  • List repositories:
az repos list

Azure Monitor

  • Create a new log analytics workspace:
az monitor log-analytics workspace create --resource-group myResourceGroup --workspace-name myWorkspace
  • List log analytics workspaces:
az monitor log-analytics workspace list --output table
  • Delete a log analytics workspace:
az monitor log-analytics workspace delete --resource-group myResourceGroup --workspace-name myWorkspace --yes

Conclusion

This guide provides a comprehensive overview of Azure CLI commands for managing a wide range of Azure services. Mastery of these commands will enable you to efficiently handle Azure resources, automate tasks, and integrate Azure services into your DevOps workflows.

--

--

No responses yet