This tutorial will show you on how to create a Azure Kubernetes Cluster (AKS) by using the Terraform tool.
- Azure Account( https://azure.microsoft.com/en-us/features/azure-portal/)
- Install Azure CLI ( https://docs.microsoft.com/en-us/cli/azure/install-azure-cli)
- Azure Login ( az login)
Set up and initialize your Terraform Folder Workspace
You Folder structure become like below;
aks-cluster.tf provisions a resource group and an AKS cluster. The
default_node_pool defines the number of VMs and the VM type the cluster uses. The
addon_profile enables the Kubernetes dashboard.
variables.tf declares the
password so Terraform can use reference its configuration:
terraform.tfvars defines the
password variables to authenticate to Azure
outputs.tf declares values that can be useful to interact with your AKS cluster
Create an Active Directory service principal account
We need to configure the provider with the
tenant_id. Set the following environment variables with the values which correspond to your account.
We can create a new Service Account by execute command below;
After you have saved your customized variables file, initialize your Terraform workspace, which will download the provider and initialize it with the values provided in your
Run / Execute Terraform and Provision the AKS cluster
It will execute below;
This process should take approximately 10 minutes. Upon successful application, your terminal prints the outputs defined in
Create and Access Kubernetes Dashboard
To verify that your cluster is configured correctly and running, you will navigate to it in your local browser. We need to create a
ClusterRoleBinding to use the Kubernetes dashboard. This gives the
cluster-admin permission to access the
kubernetes-dashboard. you don't need to configure your Terraform Kubernetes Provider since you create this using Terraform,
Finally, to access the Kubernetes dashboard, run the following command, customized with your cluster name instead of
sample-aks-. This will continue running until you stop the process by pressing
CTRL + C.
You should be able to access the Kubernetes dashboard at http://127.0.0.1:8001/.
If want to destroy any resources you create once you are done with this tutorial. Run the
destroy command and confirm with
yes in your terminal.
Recap / Summary
We had learned how to use Terraform to provision Azure Kubernetest Cluster by following steps;
- Set up and initialize your Terraform workspace
- Create an Active Directory service principal account
- Initialize Terraform
- Run / Execute Terraform and Provision the AKS cluster
- Configure kubectl locally
- Access Kubernetes Dashboard
- Clean up your tutorial workspace