To provision an Azure Kubernetes Service (AKS) cluster using the Azure Command-Line Interface (az), you can use the following steps. Make sure you have the Azure CLI installed and authenticated before you proceed.
- Open a Command Prompt or Terminal:
- On Windows, you can use Command Prompt or PowerShell.
- On Linux or macOS, use a terminal.
- Login to Azure:
az login
This command will open a browser window asking you to log in to your Azure account. - Set Azure Subscription (if you have multiple subscriptions):
az account set --subscription <subscription-id>
- Create a Resource Group:
az group create --name <resource-group-name> --location <azure-region>
Replace <resource-group-name> with your desired resource group name and <azure-region> with the Azure region you want. - Create AKS Cluster:
az aks create --resource-group <resource-group-name> --name <aks-cluster-name> --node-count <node-count> --enable-addons monitoring --generate-ssh-keys
Replacewith your desired AKS cluster name, with the number of nodes in your cluster, and adjust other parameters as needed. - –enable-addons monitoring: This flag enables monitoring addons.
- –generate-ssh-keys: This flag generates SSH keys for authentication.
- Configure kubectl to Use the New AKS Cluster:
az aks get-credentials --resource-group <resource-group-name> --name <aks-cluster-name>
This command downloads the cluster credentials and configures kubectl to use them. - Verify the AKS Cluster:
kubectl get nodes
This command should display the nodes in your AKS cluster.
That’s it! You’ve successfully provisioned an AKS cluster using the Azure CLI. Make sure to replace the placeholder values with your specific information.
To pull image from ACR (Azure Container Registry)
View available ACR
az acr list --resource-group <resource-group-name> --query "[].name" --output table
az acr list --query "[].{ResourceGroup:resourceGroup, ACRName:name, Subscription:subscriptionId}" --output table
Authenticate AKS with ACR
az aks update --resource-group <resource-group-name> --name <aks-cluster-name> --attach-acr <acr-name>
Verify ACR Integration
az aks show --resource-group <resource-group-name> --name <aks-cluster-name> --query "addonProfiles.httpApplicationRouting.config.HTTPApplicationRoutingZoneName"