- Lab
- A Cloud Guru
Create an AKS Cluster in Azure with Terraform
In this lab, using the Azure portal, you will configure the Cloud Shell and download and run the lab setup script. Next, you will import the resource group. Then, you will add your AKS, variable, and outputs to the configuration. Lastly, you will deploy your Kubernetes cluster resources and verify that the cluster is up and healthy.
Path Info
Table of Contents
-
Challenge
Set Up Cloud Shell and the Lab Environment
In the Portal
- Click the Cloud Shell icon.
- Select Bash at the prompt.
- Click Show Advanced Settings.
- Set the Cloud Shell region to the same location as the resource group.
- Select the existing resource group, and select Use Existing for the Storage Account.
- In the File share section, choose Create new and enter terraform.
- Click Create Storage.
- Download the
lab_7_setup.sh
script athttps://raw.githubusercontent.com/ACloudGuru-Resources/advanced-terraform-with-azure/main/lab_aks_cluster/lab_7_setup.sh
. - Add execute permissions to the script.
- Run the lab_7_setup.sh script.
-
Challenge
Import the Resource Group
In the Cloud Shell
- In the Cloud Shell, review the
providers.tf
. - Make note of the resource group and label and then close the file.
- Run the
az group list
command to get the subscription ID. - Import your resource group into Terraform using the resource name, label, and subscription ID.
- After the import, add the name and location of your resource group to the
providers.tf
file, so it looks like the code below:resource "azurerm_resource_group" "k8s" { name = "<RESOURCE_GROUP>" location = "<LOCATION>" }
- Save the file.
- Create an SSH key pair.
- In the Cloud Shell, review the
-
Challenge
Add the AKS Config, Variables, and Outputs to the Configuration
In the Cloud Shell
- Create the
aks.tf
file. - Define the Kubernetes cluster using the
azurerm_kubernetes_cluster
resource with a label ofk8s
. Create the configuration and use variables for the following fields:- cluster name
- dns prefix
- ssh key pair
- node count
- client id
- client secret
- resource group location
- Save the changes.
- Create the
variables.tf
file. - Define the following input variables:
- cluster name
- dns prefix
- ssh key pair
- node count
- client id
- client secret
- resource group location
- Save the changes.
- Create a file called
output.tf
. - Define the following output variables:
- resource group name
- client key
- client certificate
- client ca certificate
- cluster username
- cluster password
- kube config
- host
- Save the changes.
- Create the
-
Challenge
Deploy and Verify the Kubernetes Cluster Is Running
- Apply your configuration.
- Copy your
kube_config
to a file calledazurek8s
. - Export your
kube_config
to an environment variable. - Check the health of your cluster and make sure it is in a status of
READY
to finish the lab.
What's a lab?
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.
Provided environment for hands-on practice
We will provide the credentials and environment necessary for you to practice right within your browser.
Guided walkthrough
Follow along with the author’s guided walkthrough and build something new in your provided environment!
Did you know?
On average, you retain 75% more of your learning if you get time for practice.