Deploy and run workflows with the Dapr extension for Azure Kubernetes Service (AKS)
With Dapr Workflow, you can easily orchestrate messaging, state management, and failure-handling logic across various microservices. Dapr Workflow can help you create long-running, fault-tolerant, and stateful applications.
In this guide, you use the provided order processing workflow example to:
- Create an Azure Container Registry and an AKS cluster for this sample.
- Install the Dapr extension on your AKS cluster.
- Deploy the sample application to AKS.
- Start and query workflow instances using HTTP API calls.
The workflow example is an ASP.NET Core project with:
- A
Program.cs
file that contains the setup of the app, including the registration of the workflow and workflow activities. - Workflow definitions found in the
Workflows
directory. - Workflow activity definitions found in the
Activities
directory.
Note
Dapr Workflow is currently a beta feature and is on a self-service, opt-in basis. Beta Dapr APIs and components are provided "as is" and "as available," and are continually evolving as they move toward stable status. Beta APIs and components are not covered by customer support.
Prerequisites
- An Azure subscription with Owner or Admin role.
- The latest version of the Azure CLI
- Latest Docker
- Latest Helm
Set up the environment
Clone the sample project
Clone the example workflow application.
git clone https://github.com/Azure/dapr-workflows-aks-sample.git
Navigate to the sample's root directory.
cd dapr-workflows-aks-sample
Create a Kubernetes cluster
Create a resource group to hold the AKS cluster.
az group create --name myResourceGroup --location eastus
Create an AKS cluster.
az aks create --resource-group myResourceGroup --name myAKSCluster --node-count 2 --generate-ssh-keys
Make sure kubectl
is installed and pointed to your AKS cluster. If you use the Azure Cloud Shell, kubectl
is already installed.
For more information, see the Deploy an AKS cluster tutorial.
Deploy the application to AKS
Install Dapr on your AKS cluster
Install the Dapr extension on your AKS cluster. Before you start, make sure you have:
- Installed or updated the
k8s-extension
. - Registered the
Microsoft.KubernetesConfiguration
service provider
az k8s-extension create --cluster-type managedClusters --cluster-name myAKSCluster --resource-group myResourceGroup --name dapr --extension-type Microsoft.Dapr
Verify Dapr is installed:
kubectl get pods -A
Deploy the Redis Actor state store component
Navigate to the Deploy
directory in your forked version of the sample:
cd Deploy
Deploy the Redis component:
helm repo add bitnami https://charts.bitnami.com/bitnami
helm install redis bitnami/redis
kubectl apply -f redis.yaml
Run the application
Once Redis is deployed, deploy the application to AKS:
kubectl apply -f deployment.yaml
Expose the Dapr sidecar and the sample app:
kubectl apply -f service.yaml
export APP_URL=$(kubectl get svc/workflows-sample -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
export DAPR_URL=$(kubectl get svc/workflows-sample-dapr -o jsonpath='{.status.loadBalancer.ingress[0].ip}')
Verify that the above commands were exported:
echo $APP_URL
echo $DAPR_URL
Start the workflow
Now that the application and Dapr are deployed to the AKS cluster, you can now start and query workflow instances. Restock items in the inventory using the following API call to the sample app:
curl -X GET $APP_URL/stock/restock
Start the workflow:
curl -i -X POST $DAPR_URL/v1.0-beta1/workflows/dapr/OrderProcessingWorkflow/start?instanceID=1234 \
-H "Content-Type: application/json" \
-d '{ "input" : {"Name": "Paperclips", "TotalCost": 99.95, "Quantity": 1}}'
Expected output:
HTTP/1.1 202 Accepted
Content-Type: application/json
Traceparent: 00-00000000000000000000000000000000-0000000000000000-00
Date: Tue, 23 Apr 2024 15:35:00 GMT
Content-Length: 21
Check the workflow status:
curl -i -X GET $DAPR_URL/v1.0-beta1/workflows/dapr/1234
Expected output:
HTTP/1.1 200 OK
Content-Type: application/json
Traceparent: 00-00000000000000000000000000000000-0000000000000000-00
Date: Tue, 23 Apr 2024 15:51:02 GMT
Content-Length: 580
{
"instanceID":"1234",
"workflowName":"OrderProcessingWorkflow",
"createdAt":"2024-04-23T15:35:00.156714334Z",
"lastUpdatedAt":"2024-04-23T15:35:00.176459055Z",
"runtimeStatus":"COMPLETED",
"dapr.workflow.input":"{ \"input\" : {\"Name\": \"Paperclips\", \"TotalCost\": 99.95, \"Quantity\": 1}}",
"dapr.workflow.output":"{\"Processed\":true}"
}
Notice that the workflow status is marked as completed.
Next steps
Azure Kubernetes Service