Thursday, October 1, 2020

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

What is Azure Kubernetes Service (AKS)

Azure Kubernetes Service (AKS) is a managed container orchestration service, based on the open source Kubernetes system, which is available on the Microsoft Azure public cloud. AKS allows you to quickly deploy a production ready Kubernetes cluster in Azure, deploy and manage containerized applications more easily with a fully managed Kubernetes service. 

AKS reduces the complexity and operational overhead of managing Kubernetes by offloading much of that responsibility to Azure. As a hosted Kubernetes service, Azure handles critical tasks like health monitoring and maintenance for you. The Kubernetes masters are managed by Azure. You only manage and maintain the agent nodes. As a managed Kubernetes service, AKS is free - you only pay for the agent nodes within your clusters, not for the masters. 

Pre-requisites:

  • Azure CLI is installed on your local machine.
  • Account setup in Azure cloud.
  • Install kubectl. Click here to learn how to install on Mac

How to Create AKS Cluster using Azure CLI command?

Step 1

Make sure you are login to Azure portal first.

az login

enter your Microsoft credentials.

Step 2 - create a resource group first

az group create --name myResourceGroup --location southcentralus

Step 3 Create AKS cluster with 2 worker nodes

az aks create --resource-group myResourceGroup --name myAKSCluster --node-count 2

Display Details of Cluster

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

The above command will display Cluster details.

Step 4 - Create Azure Container Registry

Run the below command to create your own private container registry using Azure Container Registry (ACR). Make sure below red marked registry name is unique.

az acr create --resource-group myResourceGroup --name myacrrepo4321 --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 myacrrepo4321


Let's deploy some apps into AKS cluster. 

Deploy Nginx App

kubectl create -f https://raw.githubusercontent.com/kubernetes/website/master/content/en/examples/controllers/nginx-deployment.yaml

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

1 comment:

  1. Hi Sir, I am getting below when connecting to AKS cluster. Can you please help me on this how to resolve this error.
    az aks get-credentials --resource-group myResourceGroup --name myAKSCluster --overwrite-existing
    (ControlPlaneNotFound) Could not find control plane with ID 635910d0c727170001c75ea0.
    Code: ControlPlaneNotFound
    Message: Could not find control plane with ID 635910d0c727170001c75ea0.

    ReplyDelete

What is GitHub Advanced Security for Azure DevOps | Configure GitHub Advanced Security for Azure DevOps

GitHub Advanced Security for Azure DevOps brings the  secret scanning, dependency scanning  and  CodeQL code scanning  solutions already ava...