Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
Azure icon
Labs

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.

Azure icon
Labs

Path Info

Level
Clock icon Advanced
Duration
Clock icon 1h 0m
Published
Clock icon Jun 17, 2022

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    Set Up Cloud Shell and the Lab Environment

    In the Portal

    1. Click the Cloud Shell icon.
    2. Select Bash at the prompt.
    3. Click Show Advanced Settings.
    4. Set the Cloud Shell region to the same location as the resource group.
    5. Select the existing resource group, and select Use Existing for the Storage Account.
    6. In the File share section, choose Create new and enter terraform.
    7. Click Create Storage.
    8. Download the lab_7_setup.sh script at https://raw.githubusercontent.com/ACloudGuru-Resources/advanced-terraform-with-azure/main/lab_aks_cluster/lab_7_setup.sh.
    9. Add execute permissions to the script.
    10. Run the lab_7_setup.sh script.
  2. Challenge

    Import the Resource Group

    In the Cloud Shell

    1. In the Cloud Shell, review the providers.tf.
    2. Make note of the resource group and label and then close the file.
    3. Run the az group list command to get the subscription ID.
    4. Import your resource group into Terraform using the resource name, label, and subscription ID.
    5. 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>"
      }   
      
    6. Save the file.
    7. Create an SSH key pair.
  3. Challenge

    Add the AKS Config, Variables, and Outputs to the Configuration

    In the Cloud Shell

    1. Create the aks.tf file.
    2. Define the Kubernetes cluster using the azurerm_kubernetes_cluster resource with a label of k8s. Create the configuration and use variables for the following fields:
      1. cluster name
      2. dns prefix
      3. ssh key pair
      4. node count
      5. client id
      6. client secret
      7. resource group location
    3. Save the changes.
    4. Create the variables.tf file.
    5. Define the following input variables:
      1. cluster name
      2. dns prefix
      3. ssh key pair
      4. node count
      5. client id
      6. client secret
      7. resource group location
    6. Save the changes.
    7. Create a file called output.tf.
    8. Define the following output variables:
      1. resource group name
      2. client key
      3. client certificate
      4. client ca certificate
      5. cluster username
      6. cluster password
      7. kube config
      8. host
    9. Save the changes.
  4. Challenge

    Deploy and Verify the Kubernetes Cluster Is Running

    1. Apply your configuration.
    2. Copy your kube_config to a file called azurek8s.
    3. Export your kube_config to an environment variable.
    4. Check the health of your cluster and make sure it is in a status of READY to finish the lab.

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

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.

Start learning by doing today

View Plans