Deploying .NET 5 Microservices to AKS using Terraform and Helm
This blog is for a Microsoft Reactor lab for deploying a .NET Microservice to Azure Kubernetes Service by Brad McCoy — Cloud Engineering Lead from Moula.
In this lab we will be give you hands on experience on deploying applications to Azure Kubernetes Services (AKS) we will be creating the following below:
These are the steps we will take:
- Sign up for your free Azure account
- Fork Repo’s from GitHub
- Install Dependencies
- Configure Terraform
- Provision Infrastructure
- Build/Push .NET 5 API Docker image
- Deploy Image with Helm
Sign up for your free Azure account
Sign up here for your free account: https://azure.microsoft.com/en-us/free/
Fork Repo’s from GitHub
There are two repositories we will use one for the infrastructure and one for the other for the API.
Infrastructure: https://github.com/bradmccoydev/aks
Surf Report API: https://github.com/bradmccoydev/surf-report
Install Dependencies
We will now install Terraform and Helm that we will be using to deploy.
Terraform: https://learn.hashicorp.com/tutorials/terraform/install-cli
Helm: https://helm.sh/docs/intro/install/
Azure Cli: https://docs.microsoft.com/en-us/cli/azure/install-azure-cli
Docker Desktop: https://www.docker.com/products/docker-desktop
Configure Terraform
We will use remote state in terraform so we need to create a Azure storage account so that we can store the state there.
if you are not sure what remote state is you can check here: https://www.terraform.io/docs/language/state/remote.html
To create the resources in Azure use the following commands:
# Login To Azure
az login# Create Resource Group
az group create -location australiaeast -name terraformstate-rg# Create Storage Account (note: replace <name> with a distinct name)
az storage account create --name <name> --resource-group terraformstate-rg --location australiaeast --sku Standard_LRS# Create Storage Container
az storage container create --name reactorlab --account-name <name>
Provision Infrastructure
# Login To Azure (if required)
az login# Initialize Terraform
terraform init# Terraform Plan
terraform plan# Terraform Apply
terraform apply
Build/Push .NET 5 Docker image
If you don't have a dockerhub account you can sign up for free: https://hub.docker.com/
docker login
docker build . -t reactor-lab
docker tag reactor-lab bradmccoydev/reactor-lab:latest
docker push bradmccoydev/reactor-lab:latestDeploy Image with Helm
helm install reactor-lab ./chart