In this lab you will deploy Azure Container Apps, Azure Container Registry, Azure Service Bus, Azure Managed Grafana, and potentially other Azure Services (i.e., Azure Virtual Network) using Terraform. At the time of this writing some services are not available in Hashicorp's azurerm
provider so we will deploy container apps and the managed Grafana service using the AzAPI provider.
You will deploy two types of container apps to demonstrate Azure Container Apps autoscaling features. The helloworld
container app is a simple app found in the Azure Container Apps quickstart guide. This container app will be configured for HTTP scaling. Upon creation of the resources, a k6_scripts.js
file will appear in your directory. You can use to load test the application.
The other set of container apps will demonstrate autoscaling using event-driven scalers. In this case, we will be using the azure-servicebus
KEDA scaler to scale our replica counts up and down based on the number of messages in the queue. This solution includes a project called go-servicebus-sender
. This app will produce messages and add them to the queue. The other app called go-servicebus-receiver
will receive messages off the queue. Autoscaling will be applied to the message receiver app.
For both container app types, you can view the replica counts using the metrics blade within the Azure portal. You can also import a curated Azure Container Apps dashboard into your Azure Managed Grafana instance and view the metrics from there.
To import dashboards, navigate to your Azure Managed Grafana site, click on the Dashboards menu item and click the +Import button. In the Import via grafana.com textbox, enter 16592
to import the Azure / Container Apps / Container App View dashboard. You can explore and import other dashboards curated by the azuremonitorteam
.
- An Azure Subscription (e.g. Free or Student account)
- The Azure CLI
- Bash shell (e.g. macOS, Linux, Windows Subsystem for Linux (WSL), Multipass, Azure Cloud Shell, GitHub Codespaces, etc)
- The Terraform CLI
- The k6 CLI
Before you begin, clone this repository to your location of choice.
git clone https://github.com/Azure-Samples/azure-opensource-labs.git
Terraform will use your Azure CLI login context to deploy the resources into your subscription. Login to the Azure CLI and ensure you have selected the proper subscription.
az login
Optionally set the correct subscription if you have more than one.
az account set -s '<YOUR_SUBSCRIPTION_NAME>'
Change to the cloud-native/containerapps-terraform/terraform
subdirectory of this repo and run the Terraform deployment script.
cd cloud-native/containerapps-terraform/terraform
terraform init
terraform apply
NOTE: Terraform state files will be stored locally within your directory
Review the items that will be deployed by Terraform, then type yes
in the console to confirm the deployment.
For a more in depth guide on how the Terraform is put together using the AzAPI provider, go check out this blog post.
The container apps will already have autoscaling fully configured and enabled.
Open the Azure portal.
Navigate to the rg-fittingshiner
resource group to explore the deployment and its configuration.
Next, use k6 load testing tool to send load to the application URL.
This will use the k6_scripts.js file that was created by k6_load_test_script.tf based on the k6_scripts.tpl template, when we ran the terraform apply
command. It will output the const res = http.get('${INGRESS_FQDN}');
with the correct application URL for your helloworld
app.
Run the below command to send some load to your application.
k6 run --vus 200 --duration 10s k6_scripts.js
Once you have sent some traffic to the service, you can watch these videos for more details on the deployment.
If you are feeling adventurous, try implementing another container app with one of these KEDA scalers 🚀
Once you have finished exploring, you should delete the deployment to avoid any further charges.
terraform destroy