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.
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- 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/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.
- 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
- 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:
1) cluster name
2) dns prefix
3) ssh key pair
4) node count
5) client id
6) client secret
7) resource group location - Save the changes.
- Create the
variables.tf
file. - 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 - Save the changes.
- Create a file called
output.tf
. - 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 - Save the changes.
- Create the
- 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.