Thursday, October 1, 2020

How to create AKS cluster using Azure CLI | Create Kubernetes Cluster using Azure CLI

What is Azure Kubernetes Service (AKS)

AKS is a managed Kubernetes service that lets you quickly deploy and manage clusters. We will see how to create AKS cluster in Azure cloud using Azure CLI.


  • Azure CLI is installed on your local machine.
  • Account setup in Azure.

Create Resource Group

Make sure you are login to Azure portal first.

az login

You need to create a resource group first.

az group create --name myResourceGroup --location southcentralus

Create AKS cluster with 2 worker nodes

az aks create --resource-group myResourceGroup --name myAKSCluster --node-count 2 --enable-addons monitoring --generate-ssh-keys

az aks show --name myAKSCluster --resource-group myResourceGroup

The above command should display Cluster exists in Azure portal

Create Azure Container Registry

Run the below command to create your own private container registry using Azure Container Registry (ACR).

az acr create --resource-group myResourceGroup --name myacrrepo31 --sku Standard --location southcentralus

Connect to the cluster

 az aks get-credentials --resource-group myResourceGroup --name myAKSCluster --overwrite-existing

To verify the connection to your cluster, use the kubectl get command to return a list of the cluster nodes.

kubectl get nodes




# List all deployments in a specific namespace

kubectl get deployments --all-namespaces=true


For Deploying Docker images from ACR into AKS Cluster 

When you're using Azure Container Registry (ACR) with Azure Kubernetes Service (AKS), an authentication mechanism needs to be established. 
You can set up the AKS to ACR integration in a few simple commands with the Azure CLI or Azure PowerShell. This integration assigns the AcrPull role to the managed identity associated to the AKS Cluster.

For Deploying Docker images from ACR into AKS Cluster 

az aks update -n myAKSCluster -g myResourceGroup --attach-acr myacrrepo31

Let's deploy some apps into AKS cluster. 

Deploy Nginx App

kubectl create -f

Once the deployment is created, use kubectl to check on the deployments by running this command: 

kubectl get deployments

Clean up the cluster

To avoid Azure charges, you should clean up unneeded resources. When the cluster is no longer needed, use the az group delete command to remove the resource group, container service, and all related resources. 

az group delete --name myResourceGroup --yes --no-wait

Please watch the above steps in action in YouTube

No comments:

Post a Comment

How to check whether my user data passing to EC2 instance is working | AWS EC2 bootstrap script log

The cloud-init output log file ( /var/log/cloud-init-output.log ) captures console output so it is easy to debug your scripts following a la...