In Capstone project 3,we created an automated provisioned infrastructure using Terraform, EKS cluster, EC2 instances. In this we will create similar in in azure using terraform, AKS and Virtual machine and VM scale sets.
For Virtual machine scale sets configuration, we would need to configure the below:
- Resource Group
- Virtual network
- Subnet
- Public ip
- Load balance and backend pools
- Virtual machine scale sets
- Virtual machine
- Public ip and network interface for the Virtual machine
We will use terraform from azure cloud shell.
First we will check if the cloud shell has terraform:
It will already have the terraform.
Now we have to check the subsciption it is using:
It is using the correct subscription.
If you are using from other systems you will have to install azure cli and run az login
command.
We will now create new directory for terraform and initalize the git because we want to send the files to git once we have completed the task for future use
First we wil create providers.tf file which will have provider and version details:
https://github.com/kotianrakshith/AzureProj4/blob/main/providers.tf
Next we will create resourcegroup.tf :
https://github.com/kotianrakshith/AzureProj4/blob/main/resourcegroup.tf
One for randomstring.tf:
https://github.com/kotianrakshith/AzureProj4/blob/main/randomstring.tf
Next we will write for virtual network: vn.tf
https://github.com/kotianrakshith/AzureProj4/blob/main/vn.tf
Next we will write for subnet: subnet.tf
https://github.com/kotianrakshith/AzureProj4/blob/main/subnet.tf
Next we will write for publicip: publicip.tf
https://github.com/kotianrakshith/AzureProj4/blob/main/publicip.tf
Next write for loadbalancer: lb.tf
https://github.com/kotianrakshith/AzureProj4/blob/main/lb.tf
This will include the load balancer, backend address pool, load balancer probe, load balancer rule:
Now you can write for virtual machine scale sets: vmss.tf
https://github.com/kotianrakshith/AzureProj4/blob/main/vmss.tf
Now write the configuration for virtual machine: vm.tf
https://github.com/kotianrakshith/AzureProj4/blob/main/vm.tf
We have created required files for the virtual machine scale sets:
We will push it to github our porgress till here.
We have added the files and comitted:
Then we can push using git push -u origin main
We will have all the required files in github
First we will create a new resource group for kubernetes cluser:
aksrg.tf
https://github.com/kotianrakshith/AzureProj4/blob/main/aksrg.tf
First we will write a configuration for log analytics workspace (optional), we can assign this to our aks cluser
loganalyticsworkspace.tf
https://github.com/kotianrakshith/AzureProj4/blob/main/loganalyticsworkspace.tf
Now we will write a configuration file for AKS: aks.tf
https://github.com/kotianrakshith/AzureProj4/blob/main/aks.tf
Now we will add this also to staging and commit it and push it to github.and then we will have all the files both in our system and github:
Github link: https://github.com/kotianrakshith/AzureProj4
First we will run initializing command to download required providers:
terrafrom init
Then we will run terraform plan to check if there are any errors and if not, what are the resource which will be built:
terraform plan
Now we will run the apply command to build all this 16 resource
terraform apply
This will prompt for approval, type yes
This will take some time and once all are created it will inform that all resource are created:
First you can go to All resource in azure portal and you can see all the resource that is created
Now you can check the required deployment:
VM: You can see our virtual machine is created in the resource group we specified
VMSS: You can see that our scale set is created(One for AKS cluster, One which we created)
AKS: You can go to kubernetes service and check that your cluster is created in mentioned resource group:
That completes the building infrastrcutre using IaC tool Terraform. We can see all the required dependency are created with minimal time and the code can be reused.
You can delete all the infrastructure using simple command: terraform destroy
It will ask for approval:
Once completed all the resource will be deleted. You can check in all resources if ther resources has been removed: