|
| 1 | +--- |
| 2 | +title: Deploy and run workflows with the Dapr extension for Azure Kubernetes Service (AKS) |
| 3 | +description: Learn how to deploy and run Dapr Workflow on your Azure Kubernetes Service (AKS) clusters via the Dapr extension. |
| 4 | +author: hhunter-ms |
| 5 | +ms.author: hannahhunter |
| 6 | +ms.reviewer: nuversky |
| 7 | +ms.service: azure-kubernetes-service |
| 8 | +ms.topic: article |
| 9 | +ms.date: 04/05/2023 |
| 10 | +ms.custom: devx-track-azurecli |
| 11 | +--- |
| 12 | + |
| 13 | +# Deploy and run workflows with the Dapr extension for Azure Kubernetes Service (AKS) |
| 14 | + |
| 15 | +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. |
| 16 | + |
| 17 | +In this guide, you use the [provided order processing workflow example][dapr-workflow-sample] to: |
| 18 | + |
| 19 | +> [!div class="checklist"] |
| 20 | +> - Create an Azure Container Registry and an AKS cluster for this sample. |
| 21 | +> - Install the Dapr extension on your AKS cluster. |
| 22 | +> - Deploy the sample application to AKS. |
| 23 | +> - Start and query workflow instances using HTTP API calls. |
| 24 | +
|
| 25 | +The workflow example is an ASP.NET Core project with: |
| 26 | +- A [`Program.cs` file][dapr-program] that contains the setup of the app, including the registration of the workflow and workflow activities. |
| 27 | +- Workflow definitions found in the [`Workflows` directory][dapr-workflow-dir]. |
| 28 | +- Workflow activity definitions found in the [`Activities` directory][dapr-activities-dir]. |
| 29 | + |
| 30 | +> [!NOTE] |
| 31 | +> Dapr Workflow is currently an [alpha][dapr-workflow-alpha] feature and is on a self-service, opt-in basis. Alpha Dapr APIs and components are provided "as is" and "as available," and are continually evolving as they move toward stable status. Alpha APIs and components are not covered by customer support. |
| 32 | +
|
| 33 | +## Prerequisites |
| 34 | + |
| 35 | +- An [Azure subscription](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) with Owner or Admin role. |
| 36 | +- The latest version of the [Azure CLI][install-cli] |
| 37 | +- Latest [Docker][docker] |
| 38 | +- Latest [Helm][helm] |
| 39 | + |
| 40 | +## Set up the environment |
| 41 | + |
| 42 | +### Clone the sample project |
| 43 | + |
| 44 | +Clone the example workflow application. |
| 45 | + |
| 46 | +```sh |
| 47 | +git clone https://github.com/Azure/dapr-workflows-aks-sample.git |
| 48 | +``` |
| 49 | + |
| 50 | +Navigate to the sample's root directory. |
| 51 | + |
| 52 | +```sh |
| 53 | +cd dapr-workflows-aks-sample |
| 54 | +``` |
| 55 | + |
| 56 | +### Create a Kubernetes cluster |
| 57 | + |
| 58 | +Create a resource group to hold the AKS cluster. |
| 59 | + |
| 60 | +```sh |
| 61 | +az group create --name myResourceGroup --location eastus |
| 62 | +``` |
| 63 | + |
| 64 | +Create an AKS cluster. |
| 65 | + |
| 66 | +```sh |
| 67 | +az aks create --resource-group myResourceGroup --name myAKSCluster --node-count 2 --generate-ssh-keys |
| 68 | +``` |
| 69 | + |
| 70 | +[Make sure `kubectl` is installed and pointed to your AKS cluster.][kubectl] If you use [the Azure Cloud Shell][az-cloud-shell], `kubectl` is already installed. |
| 71 | + |
| 72 | +For more information, see the [Deploy an AKS cluster][cluster] tutorial. |
| 73 | + |
| 74 | +## Deploy the application to AKS |
| 75 | + |
| 76 | +### Install Dapr on your AKS cluster |
| 77 | + |
| 78 | +Install the Dapr extension on your AKS cluster. Before you start, make sure you've: |
| 79 | +- [Installed or updated the `k8s-extension`][k8s-ext]. |
| 80 | +- [Registered the `Microsoft.KubernetesConfiguration` service provider][k8s-sp] |
| 81 | + |
| 82 | +```sh |
| 83 | +az k8s-extension create --cluster-type managedClusters --cluster-name myAKSCluster --resource-group myResourceGroup --name dapr --extension-type Microsoft.Dapr |
| 84 | +``` |
| 85 | + |
| 86 | +Verify Dapr has been installed by running the following command: |
| 87 | + |
| 88 | +```sh |
| 89 | +kubectl get pods -A |
| 90 | +``` |
| 91 | + |
| 92 | +### Deploy the Redis Actor state store component |
| 93 | + |
| 94 | +Navigate to the `Deploy` directory in your forked version of the sample: |
| 95 | + |
| 96 | +```sh |
| 97 | +cd Deploy |
| 98 | +``` |
| 99 | + |
| 100 | +Deploy the Redis component: |
| 101 | + |
| 102 | +```sh |
| 103 | +helm repo add bitnami https://charts.bitnami.com/bitnami |
| 104 | +helm install redis bitnami/redis |
| 105 | +kubectl apply -f redis.yaml |
| 106 | +``` |
| 107 | + |
| 108 | +### Run the application |
| 109 | + |
| 110 | +Once you've deployed Redis, deploy the application to AKS: |
| 111 | + |
| 112 | +```sh |
| 113 | +kubectl apply -f deployment.yaml |
| 114 | +``` |
| 115 | + |
| 116 | +Expose the Dapr sidecar and the sample app: |
| 117 | + |
| 118 | +```sh |
| 119 | +kubectl apply -f service.yaml |
| 120 | +export APP_URL=$(kubectl get svc/workflows-sample -o jsonpath='{.status.loadBalancer.ingress[0].ip}') |
| 121 | +export DAPR_URL=$(kubectl get svc/workflows-sample-dapr -o jsonpath='{.status.loadBalancer.ingress[0].ip}') |
| 122 | +``` |
| 123 | + |
| 124 | +Verify that the above commands were exported: |
| 125 | + |
| 126 | +```sh |
| 127 | +echo $APP_URL |
| 128 | +echo $DAPR_URL |
| 129 | +``` |
| 130 | + |
| 131 | +## Start the workflow |
| 132 | + |
| 133 | +Now that the application and Dapr have been deployed to the AKS cluster, you can now start and query workflow instances. Begin by making an API call to the sample app to restock items in the inventory: |
| 134 | + |
| 135 | +```sh |
| 136 | +curl -X GET $APP_URL/stock/restock |
| 137 | +``` |
| 138 | + |
| 139 | +Start the workflow: |
| 140 | + |
| 141 | +```sh |
| 142 | +curl -X POST $DAPR_URL/v1.0-alpha1/workflows/dapr/OrderProcessingWorkflow/1234/start \ |
| 143 | + -H "Content-Type: application/json" \ |
| 144 | + -d '{ "input" : {"Name": "Paperclips", "TotalCost": 99.95, "Quantity": 1}}' |
| 145 | +``` |
| 146 | + |
| 147 | +Expected output: |
| 148 | + |
| 149 | +```json |
| 150 | +{"instance_id":"1234"} |
| 151 | +``` |
| 152 | + |
| 153 | +Check the workflow status: |
| 154 | + |
| 155 | +```sh |
| 156 | +curl -X GET $DAPR_URL/v1.0-alpha1/workflows/dapr/OrderProcessingWorkflow/1234 |
| 157 | +``` |
| 158 | + |
| 159 | +Expected output: |
| 160 | + |
| 161 | +```json |
| 162 | +{ |
| 163 | + "WFInfo": |
| 164 | + { |
| 165 | + "instance_id":"1234" |
| 166 | + }, |
| 167 | + "start_time":"2023-03-03T19:19:16Z", |
| 168 | + "metadata": |
| 169 | + { |
| 170 | + "dapr.workflow.custom_status":"", |
| 171 | + "dapr.workflow.input":"{\"Name\":\"Paperclips\",\"Quantity\":1,\"TotalCost\":99.95}", |
| 172 | + "dapr.workflow.last_updated":"2023-03-03T19:19:33Z", |
| 173 | + "dapr.workflow.name":"OrderProcessingWorkflow", |
| 174 | + "dapr.workflow.output":"{\"Processed\":true}", |
| 175 | + "dapr.workflow.runtime_status":"COMPLETED" |
| 176 | + } |
| 177 | +} |
| 178 | +``` |
| 179 | + |
| 180 | +Notice that the workflow status is marked as completed. |
| 181 | + |
| 182 | +## Next steps |
| 183 | + |
| 184 | +[Learn how to add configuration settings to the Dapr extension on your AKS cluster][dapr-config]. |
| 185 | + |
| 186 | +<!-- Links Internal --> |
| 187 | +[deploy-cluster]: ./tutorial-kubernetes-deploy-cluster.md |
| 188 | +[install-cli]: /cli/azure/install-azure-cli |
| 189 | +[k8s-ext]: ./dapr.md#set-up-the-azure-cli-extension-for-cluster-extensions |
| 190 | +[cluster]: ./tutorial-kubernetes-deploy-cluster.md |
| 191 | +[k8s-sp]: ./dapr.md#register-the-kubernetesconfiguration-service-provider |
| 192 | +[dapr-config]: ./dapr-settings.md |
| 193 | +[az-cloud-shell]: ./learn/quick-kubernetes-deploy-powershell.md#azure-cloud-shell |
| 194 | +[kubectl]: ./tutorial-kubernetes-deploy-cluster.md#connect-to-cluster-using-kubectl |
| 195 | + |
| 196 | +<!-- Links External --> |
| 197 | +[dapr-workflow-sample]: https://github.com/Azure/dapr-workflows-aks-sample |
| 198 | +[dapr-program]: https://github.com/Azure/dapr-workflows-aks-sample/blob/main/Program.cs |
| 199 | +[dapr-workflow-dir]: https://github.com/Azure/dapr-workflows-aks-sample/tree/main/Workflows |
| 200 | +[dapr-activities-dir]: https://github.com/Azure/dapr-workflows-aks-sample/tree/main/Activities |
| 201 | +[dapr-workflow-alpha]: https://docs.dapr.io/operations/support/support-preview-features/#current-preview-features |
| 202 | +[deployment-yaml]: https://github.com/Azure/dapr-workflows-aks-sample/blob/main/Deploy/deployment.yaml |
| 203 | +[docker]: https://docs.docker.com/get-docker/ |
| 204 | +[helm]: https://helm.sh/docs/intro/install/ |
0 commit comments