Quickstart: Deploy an application using the Dapr cluster extension (preview) for Azure Kubernetes Service (AKS)

In this quickstart, you will get familiar with using the Dapr cluster extension in an AKS cluster. You will be deploying a hello world example, consisting of a Python application that generates messages and a Node application that consumes and persists them.

Important

AKS preview features are available on a self-service, opt-in basis. Previews are provided "as is" and "as available," and they're excluded from the service-level agreements and limited warranty. AKS previews are partially covered by customer support on a best-effort basis. As such, these features aren't meant for production use. For more information, see the following support articles:

Prerequisites

Clone the repository

To obtain the files you'll be using to deploy the sample application, clone the Quickstarts repository and change to the hello-kubernetes directory:

git clone https://github.com/dapr/quickstarts.git
cd quickstarts/hello-kubernetes

Create and configure a state store

Dapr can use a number of different state stores (Redis, CosmosDB, DynamoDB, Cassandra, etc.) to persist and retrieve state. For this example, we will use Redis.

Create a Redis store

  1. Open the Azure portal to start the Azure Redis Cache creation flow.
  2. Fill out the necessary information
  3. Click “Create” to kickoff deployment of your Redis instance.
  4. Take note of the hostname of your Redis instance, which you can retrieve from the “Overview” in Azure. It should look like xxxxxx.redis.cache.windows.net:6380.
  5. Once your instance is created, you’ll need to grab your access key. Navigate to “Access Keys” under “Settings” and create a Kubernetes secret to store your Redis password:
kubectl create secret generic redis --from-literal=redis-password=<your-redis-password>

Configure the Dapr components

Once your store is created, you will need to add the keys to the redis.yaml file in the deploy directory of the Hello World repository. Replace the redisHost value with your own Redis master address, and the redisPassword with your own Secret. You can learn more here.

You will also need to add the following two lines below redisPassword to enable connection over TLS:

- name: redisPassword
    secretKeyRef:
      name: redis
      key: redis-password
- name: enableTLS
  value: true

Apply the configuration

Apply the redis.yaml file:

kubectl apply -f ./deploy/redis.yaml

And verify that your state store was successfully configured in the output:

component.dapr.io/statestore created

Deploy the Node.js app with the Dapr sidecar

Apply the Node.js app's deployment to your cluster:

kubectl apply -f ./deploy/node.yaml

Note

Kubernetes deployments are asynchronous. This means you'll need to wait for the deployment to complete before moving on to the next steps. You can do so with the following command:

kubectl rollout status deploy/nodeapp

This will deploy the Node.js app to Kubernetes. The Dapr control plane will automatically inject the Dapr sidecar to the Pod. If you take a look at the node.yaml file, you will see how Dapr is enabled for that deployment:

  • dapr.io/enabled: true - this tells the Dapr control plane to inject a sidecar to this deployment.

  • dapr.io/app-id: nodeapp - this assigns a unique ID or name to the Dapr application, so it can be sent messages to and communicated with by other Dapr apps.

To access your service, obtain and make note of the EXTERNAL-IP via kubectl:

kubectl get svc nodeapp

Verify the service

To call the service, run:

curl $EXTERNAL_IP/ports

You should see output similar to the following:

{"DAPR_HTTP_PORT":"3500","DAPR_GRPC_PORT":"50001"}

Next, submit an order to the application:

curl --request POST --data "@sample.json" --header Content-Type:application/json $EXTERNAL_IP/neworder

Confirm the order has been persisted by requesting it:

curl $EXTERNAL_IP/order

You should see output similar to the following:

{ "orderId": "42" }

Tip

This is a good time to get acquainted with the Dapr dashboard- a convenient interface to check status, information and logs of applications running on Dapr. The following command will make it available on http://localhost:8080/:

kubectl port-forward svc/dapr-dashboard -n dapr-system 8080:8080

Deploy the Python app with the Dapr sidecar

Take a quick look at the Python app. Navigate to the Python app directory in the hello-kubernetes quickstart and open app.py.

This is a basic Python app that posts JSON messages to localhost:3500, which is the default listening port for Dapr. You can invoke the Node.js application's neworder endpoint by posting to v1.0/invoke/nodeapp/method/neworder. The message contains some data with an orderId that increments once per second:

n = 0
while True:
    n += 1
    message = {"data": {"orderId": n}}

    try:
        response = requests.post(dapr_url, json=message)
    except Exception as e:
        print(e)

    time.sleep(1)

Deploy the Python app to your Kubernetes cluster:

kubectl apply -f ./deploy/python.yaml

Note

As with above, the following command will wait for the deployment to complete:

kubectl rollout status deploy/pythonapp

Observe messages and confirm persistence

Now that both the Node.js and Python applications are deployed, watch messages come through.

Get the logs of the Node.js app:

kubectl logs --selector=app=node -c node --tail=-1

If the deployments were successful, you should see logs like this:

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 state

Call the Node.js app's order endpoint to get the latest order. Grab the external IP address that you saved before and, append "/order" and perform a GET request against it (enter it into your browser, use Postman, or curl it!):

curl $EXTERNAL_IP/order
{"orderID":"42"}

You should see the latest JSON in the response.

Clean up resources

Use the az group delete command to remove the resource group, the AKS cluster, namespace, and all related resources.

az group delete --name MyResourceGroup

Next steps

After successfully deploying this sample application: