Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
In this quickstart, you use the Dapr extension in an AKS or Arc-enabled Kubernetes cluster. You deploy a hello world example, which consists of a Python application that generates messages and a Node.js application that consumes and persists the messages.
Prerequisites
- An Azure subscription. If you don't have one, you can create a free account.
- Azure CLI installed
- An AKS cluster with:
- Workload identity enabled
- Managed identity created in the same subscription
- A Kubernetes service account
- Federated identity credential
- Dapr extension installed on the AKS cluster
- kubectl installed locally
Clone the repository
Clone the Dapr quickstart repository using the
git clonecommand.git clone https://github.com/Azure-Samples/dapr-aks-extension-quickstart.gitChange to the
dapr-aks-extension-quickstartdirectory.cd dapr-aks-extension-quickstart
Create and configure a Redis store
Open the Azure portal to start the Azure Managed Redis creation flow.
Fill out the recommended information according to the Create an Azure Managed Redis instance quickstart.
Select Create to start the Redis instance deployment.
Verify resource information
Once the Redis resource is deployed, navigate to its overview page.
Take note of:
- The hostname, found in the Essentials section of the resource overview page. The hostname format looks similar to:
<your-cache-name>.<region>.redis.azure.net. - The SSL port, found in Settings > Advanced settings. The default value is
10000.
- The hostname, found in the Essentials section of the resource overview page. The hostname format looks similar to:
In your terminal, enable access-key authentication on the default database.
az redisenterprise database update \ --cluster-name <REDIS_NAME> \ --resource-group <RESOURCE_GROUP> \ --access-keys-auth EnabledRetrieve the primary key for the default database and save it to an environment variable.
export REDIS_PRIMARY_KEY=$(az redisenterprise database list-keys \ --cluster-name <REDIS_NAME> \ --resource-group <RESOURCE_GROUP> \ --query primaryKey \ -o tsv)
Enable public network access
For this scenario, your Azure Managed Redis instance uses public network access. Be sure to clean up resources after you finish with this quickstart.
In the resource menu, under Settings, select Networking.
Set Public network access to Enabled.
Configure the Dapr components
In the redis.yaml file, you configure the component to use access-key authentication with TLS.
- name: redisPassword
secretKeyRef:
name: redis-secret
key: redisPassword
- name: useEntraID
value: "false"
- name: enableTLS
value: true
In your preferred code editor, navigate to the deploy directory in the sample repo and open redis.yaml.
For
redisHost, replace the placeholder<REDIS_HOST>:10000value with the Azure Managed Redis hostname you saved earlier from the Azure portal.- name: redisHost value: <your-cache-name>.<region>.redis.azure.net:10000Create the Kubernetes secret used by
redisPassword.kubectl create secret generic redis-secret \ --from-literal=redisPassword="$REDIS_PRIMARY_KEY"
Apply the configuration
Apply the redis.yaml file using the kubectl apply command.
kubectl apply -f ./deploy/redis.yaml
Expected output
component.dapr.io/statestore created
Deploy the Node.js app with the Dapr sidecar
Configure the Node.js app
Go to the
deploydirectory and open workload-identity.yaml.Replace
<MANAGED_IDENTITY_CLIENT_ID>with the client ID of the user-assigned managed identity you created.Apply the service account manifest before you deploy app manifests.
kubectl apply -f ./deploy/workload-identity.yaml
In node.yaml, the pod spec uses the workload identity label and the shared workload-sa service account:
labels:
app: node
azure.workload.identity/use: "true"
Apply the configuration
Apply the Node.js app deployment to your cluster using the
kubectl applycommand.kubectl apply -f ./deploy/node.yamlKubernetes deployments are asynchronous, so before moving on to the next steps, verify the deployment is complete with the following command:
kubectl rollout status deploy/nodeappAccess your service using the
kubectl get svccommand.kubectl get svc nodeappMake note of the
EXTERNAL-IPin the output, and set it as an environment variable.export EXTERNAL_IP=<EXTERNAL-IP>
Verify the Node.js service
Using
curl, call the service with yourEXTERNAL-IP.curl $EXTERNAL_IP/portsExample output
{"DAPR_HTTP_ENDPOINT":"http://localhost:3500","DAPR_GRPC_ENDPOINT":"http://localhost:50001"}Submit an order to the application.
curl --request POST --data "@sample.json" --header Content-Type:application/json $EXTERNAL_IP/neworderConfirm the order.
curl $EXTERNAL_IP/orderExpected output
{ "orderId": "42" }
Deploy the Python app with the Dapr sidecar
Configure the Python app
In python.yaml, the pod spec uses the workload identity label and the shared workload-sa service account:
labels:
app: python
azure.workload.identity/use: "true"
Apply the configuration
Deploy the Python app to your Kubernetes cluster using the
kubectl applycommand.kubectl apply -f ./deploy/python.yamlKubernetes deployments are asynchronous, so before moving on to the next steps, verify the deployment is complete with the following command:
kubectl rollout status deploy/pythonapp
Observe messages and confirm persistence
Now that both the Node.js and Python applications are deployed, you can watch messages come through.
Get the logs of the Node.js app using the
kubectl logscommand.kubectl logs --selector=app=node -c node --tail=-1Expected output
Got a new order! Order ID: 1 Successfully persisted state Got a new order! Order ID: 2 Successfully persisted state Got a new order! Order ID: 3 Successfully persisted stateUsing
curl, call the Node.js app's order endpoint to get the latest order.curl $EXTERNAL_IP/orderYou should see the latest JSON output in the response.
Clean up resources
If you no longer plan to use the resources from this quickstart, you can remove the resource group, cluster, namespace, and all related resources using the az group delete command.
az group delete --name <your-resource-group>