Azure Hands-On Lab - Building Azure AKS Cluster using Terraform
Azure Learning Path for Cloud and DevOps Engineers
📝Introduction
This hands-on lab, where we walk through setting up an Azure AKS Cluster using Terraform.
📝Log in to the Azure Management Console
Using your credentials, make sure you're using the right Region. In my case, I am using the region East US
available in my Cloud Playground Sandbox.
📌Note: You can also use the VSCode tool or from your local PowerShell to connect to Azure PowerShell
More information on how to set up it is on the link.
📝Prerequisites:
Update to PowerShell 5.1, if needed.
Install .NET Framework 4.7.2 or later.
Visual Code
Web Browser (Chrome, Edge)
📝Setting an Azure Storage Account to Load PowerShell
- Click the Cloud Shell icon
(>_)
at the top of the page.
- Click PowerShell.
- Click Show Advanced Settings. Use the combo box under Cloud Shell region to select the Region. Under Resource Group and Storage account(It's a globally unique name), enter a name for both. In the box under File Share, enter a name. Click ***Create storage (***if you don't have any yet).
📝Set Up Terraform Environment
You can fork this repo supporting you on this creation.
Install Terraform on your local machine if you haven't already. You can download it and follow the installation instructions.
Set up your Azure credentials by creating a service principal or using Azure CLI.
📝Prepare Terraform Configuration Files
Create a directory for your Terraform configuration.
Inside the directory, create the following files:
main.tf - Contains the main Terraform configuration
variables.tf - Contains variables that assign dynamic values to resource attributes
📝Initialize Terraform
Open a terminal and navigate to the directory where you saved your Terraform configuration files.
Run the following command to initialize Terraform:
terraform init
In case, you already have a resource group created in your subscription, you can follow the same procedure that I used:
#To check in Azure the info for the existing resource group. Follow the instructions highlighted on the terminal. az login #To import the existing resource group terraform import "azurerm_resource_group.<name_rg>" "/subscriptions/<TenantId>
After initialization, run the following commands to validate the code and preview the changes Terraform will make:
terraform validate terraform plan -out=tfplan
📌Note: This will do the dry run and tell what resources it will build, without actually building them.
If the plan looks good, run the below command to build all the required infrastructure:
terraform apply tfplan
📝Checking the nodes using Kubectl on Azure CLI
Once Terraform finishes deploying the infrastructure, you can check the nodes using the Kubectl command-line tool. Here are some commands:
kubectl get node -o wide
kubectl cluster-info
kubectl get svc
kubectl get namespaces
kubectl get events
📌Note - At the end of each hands-on Lab, always clean up all resources previously created to avoid being charged.
Congratulations — you have completed this hands-on lab covering the basics of Building Azure AKS Cluster using Terraform to deploy it.
Thank you for reading. I hope you understood and learned something helpful from my blog.
Please follow me on Cloud&DevOpsLearn and LinkedIn, franciscojblsouza