Tutorial: Deploy a Dapr application to Azure Container Apps with an Azure Resource Manager or Bicep template
Dapr (Distributed Application Runtime) is a runtime that helps you build resilient stateless and stateful microservices. In this tutorial, a sample Dapr solution is deployed to Azure Container Apps via an Azure Resource Manager (ARM) or Bicep template.
You learn how to:
- Create an Azure Blob Storage for use as a Dapr state store
- Deploy a Container Apps environment to host container apps
- Deploy two dapr-enabled container apps: one that produces orders and one that consumes orders and stores them
- Assign a user-assigned identity to a container app and supply it with the appropiate role assignment to authenticate to the Dapr state store
- Verify the interaction between the two microservices.
With Azure Container Apps, you get a fully managed version of the Dapr APIs when building microservices. When you use Dapr in Azure Container Apps, you can enable sidecars to run next to your microservices that provide a rich set of capabilities.
In this tutorial, you deploy the solution from the Dapr Hello World quickstart.
The application consists of:
- A client (Python) container app to generate messages.
- A service (Node) container app to consume and persist those messages in a state store
The following architecture diagram illustrates the components that make up this tutorial:
- An Azure account with an active subscription is required. If you don't already have one, you can create an account for free.
- A GitHub Account. If you don't already have one, sign up for free.
First, sign in to Azure.
Ensure you're running the latest version of the CLI via the upgrade command and then install the Azure Container Apps extension for the Azure CLI.
az extension add --name containerapp --upgrade
Now that the current extension or module is installed, register the
Next, set the following environment variables:
With these variables defined, you can create a resource group to organize the services needed for this tutorial.
Prepare the GitHub repository
Go to the repository holding the ARM and Bicep templates that's used to deploy the solution.
Select the Fork button at the top of the repository to fork the repo to your account.
Now you can clone your fork to work with it locally.
Use the following git command to clone your forked repo into the acadapr-templates directory.
git clone https://github.com/$GITHUB_USERNAME/Tutorial-Deploy-Dapr-Microservices-ACA.git acadapr-templates
The template deploys:
- a Container Apps environment
- a Log Analytics workspace associated with the Container Apps environment
- an Application Insights resource for distributed tracing
- a blob storage account and a default storage container
- a Dapr component for the blob storage account
- the node, Dapr-enabled container app with a user-assigned managed identity: hello-k8s-node
- the python, Dapr-enabled container app: hello-k8s-python
- an Active Directory role assignment for the node app used by the Dapr component to establish a connection to blob storage
Navigate to the acadapr-templates directory and run the following command:
A warning (BCP081) might be displayed. This warning has no effect on the successful deployment of the application.
This command deploys:
- the Container Apps environment and associated Log Analytics workspace for hosting the hello world Dapr solution
- an Application Insights instance for Dapr distributed tracing
nodeappapp server running on
targetPort: 3000with Dapr enabled and configured using:
"appPort": 3000, and a user-assigned identity with access to the Azure Blob storage via a Storage Data Contributor role assignment
- A Dapr component of
"type": "state.azure.blobstorage"scoped for use by the
nodeappfor storing state
- the Dapr-enabled, headless
pythonappthat invokes the
nodeappservice using Dapr service invocation
Verify the result
Confirm successful state persistence
You can confirm that the services are working correctly by viewing data in your Azure Storage account.
Open the Azure portal in your browser.
Go to the newly created storage account in your resource group.
Select Containers from the menu on the left side.
Select the created container.
Verify that you can see the file named
orderin the container.
Select the file.
Select the Edit tab.
Select the Refresh button to observe updates.
Data logged via a container app are stored in the
ContainerAppConsoleLogs_CL custom table in the Log Analytics workspace. You can view logs through the Azure portal or from the command line. Wait a few minutes for the analytics to arrive for the first time before you query the logged data.
Use the following command to view logs in bash or PowerShell.
LOG_ANALYTICS_WORKSPACE_CLIENT_ID=`az containerapp env show --name $CONTAINERAPPS_ENVIRONMENT --resource-group $RESOURCE_GROUP --query properties.appLogsConfiguration.logAnalyticsConfiguration.customerId --out tsv`
az monitor log-analytics query \
--workspace "$LOG_ANALYTICS_WORKSPACE_CLIENT_ID" \
--analytics-query "ContainerAppConsoleLogs_CL | where ContainerAppName_s == 'nodeapp' and (Log_s contains 'persisted' or Log_s contains 'order') | project ContainerAppName_s, Log_s, TimeGenerated | take 5" \
The following output demonstrates the type of response to expect from the command.
ContainerAppName_s Log_s TableName TimeGenerated
-------------------- ------------------------------- ------------- ------------------------
nodeapp Got a new order! Order ID: 61 PrimaryResult 2021-10-22T21:31:46.184Z
nodeapp Successfully persisted state. PrimaryResult 2021-10-22T21:31:46.184Z
nodeapp Got a new order! Order ID: 62 PrimaryResult 2021-10-22T22:01:57.174Z
nodeapp Successfully persisted state. PrimaryResult 2021-10-22T22:01:57.174Z
nodeapp Got a new order! Order ID: 63 PrimaryResult 2021-10-22T22:45:44.618Z
Clean up resources
Once you're done, run the following command to delete your resource group along with all the resources you created in this tutorial.
pythonapp continuously makes calls to
nodeapp with messages that get persisted into your configured state store, it is important to complete these cleanup steps to avoid ongoing billable operations.
Having issues? Let us know on GitHub by opening an issue in the Azure Container Apps repo.