How to Configure AKS cluster using Azure Portal and Terraform

Gopal GuptaGopal Gupta
4 min read

What is Kubernetes?

Kubernetes, also known as K8s, is an open-source system for automating the deployment, scaling, and management of containerized applications. It groups containers that make up an application into logical units for easy management and discovery.

Kubernetes Architecture Diagram

Kubernetes Architecture Diagram : Perfectly Fits Components

What is an AKS cluster?

AKS (Azure Kubernetes Service) is Azure’s managed container service and it is an open-source fully managed container orchestration service. It manages your hosted Kubernetes environment, making it simple to deploy and manage containerized applications without container orchestration expertise, divesting much of that responsibility to Azure. This service offers to provision, scaling, and upgrades of resources as per requirement or demand without any downtime in the Kubernetes cluster.

Prerequisite

  1. Azure portal account.

  2. Azure CLI installed.

  3. Terraform installed.

Configure AKS Cluster Using the Azure portal

Steps:

  1. Login to the Azure portal and click the Kubernetes services or you can search for it on the search bar.

  2. Click on Create --> Create a Kubernetes cluster

  3. As I am on free trial, so I filled that as Subscription --> ResourceGroup ( I created a new RG i.e AKS-RG)

  4. Fill in the Cluster details as per your requirement. As I am doing it for testing propose and do not want to incur much costs, I choose the below details.

  5. Choose the node size as per your requirement. You can change the size and number of CPU and RAM --> Scale mode (autoscale) --> Node Count range(min-1 and max-2)

  6. Keep all things as default. If you want to add extra node pools you can add them.

  7. Keep below all things as default and navigate to Review + create section. Click on Create.

Connecting to AKS cluster

Steps:

  1. Once the cluster is created --> select your cluster --> Connect --> Azure CLI.

    You will see the steps to connect to the cluster.

  2. After you have downloaded Azure CLI on your system. Run the command

    \>> az login

    A window will pop out which will ask for your credentials to your Azure portal. Login to that using your credentials.

    Note: If you find the below error then follow the next steps.

  3. After you log in, if you see the above error then go to your portal --> search tenant properties --> Yes (Access management for Azure Resources)

  4. Now login again. You have been successfully logged in.

  5. Follows the remaining commands for AKS Configuration as shown below.

  6. Kudos you have been connected to the AKS cluster.

AKS Cluster Provisioning through Terraform

Steps:

  1. Create a provider.tf configuration file with the below details.

     provider "azurerm" {
       features {}
         subscription_id   = "*************"
         tenant_id         = "*************"
    
     }
    
  2. Create a resource group as shown below.

     resource "azurerm_resource_group" "resource-grp" {
       name     = "cluster-rg"
       location = "Central India"
     }
    
  3. Create a resource block for AKS cluster configuration as shown below.

     resource "azurerm_kubernetes_cluster" "example" {
       name                = "aks-cluster"
       location            = azurerm_resource_group.resource-grp.location
       resource_group_name = azurerm_resource_group.resource-grp.name
       dns_prefix          = "exampleaks1"
       kubernetes_version = "1.25.6"
    
       default_node_pool {
         name       = "default"
         node_count = 1
         vm_size    = "Standard_D2_v2"
       }
    
       identity {
         type = "SystemAssigned"
       }
    
       tags = {
         Environment = "Testing"
       }
     }
    

Now run terraform init ---> terraform plan --->terraform apply command to create an cluster.

You can view your cluster has been created and to connect it follow the above procedure.

Visit this GitHub link for terraform code.

This blog is Part I of the blog name "Deploy a Web App to an AKS Cluster using AWS Codepipeline and ArgoCD" for which an AKS cluster is needed. Please check out my blog for more details.

Thank you for reading my blog. Happy learning

References:

  1. https://developer.hashicorp.com/terraform/tutorials/kubernetes/aks

  2. https://azure.microsoft.com/en-in/products/kubernetes-service

0
Subscribe to my newsletter

Read articles from Gopal Gupta directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Gopal Gupta
Gopal Gupta

I am DevOps Engineer with 1 plus year of experience. I am 2x AWS certified and also Terraform Certified. I have good knowledge in DevOps tools like Docker, Kubernetes, Linux, Git, Terraform etc.