Skip to content

Commit a27602f

Browse files
authored
Merge pull request #178185 from Nickomang/aks-dapr-qs
Dapr fast follow and Quickstart
2 parents 45ffdd4 + a8d55fc commit a27602f

File tree

3 files changed

+245
-7
lines changed

3 files changed

+245
-7
lines changed

articles/aks/TOC.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
items:
2727
- name: Develop with Helm
2828
href: quickstart-helm.md
29+
- name: Develop with Dapr (preview)
30+
href: quickstart-dapr.md
2931
- name: Subscribe to AKS events with Event Grid (Preview)
3032
href: quickstart-event-grid.md
3133
- name: Tutorials
@@ -370,7 +372,7 @@
370372
href: howto-deploy-java-liberty-app.md
371373
- name: Use Azure API Management
372374
href: ../api-management/api-management-kubernetes.md
373-
- name: Use Dapr
375+
- name: Use Dapr (preview)
374376
href: dapr.md
375377
maintainContext: true
376378
- name: Deploy a service mesh

articles/aks/dapr.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,31 +32,33 @@ Once Dapr is installed on your AKS cluster, your application services now have t
3232
> [!WARNING]
3333
> If you install Dapr through the AKS extension, our recommendation is to continue using the extension for future management of Dapr instead of the Dapr CLI. Combining the two tools can cause conflicts and result in undesired behavior.
3434
35+
## Supported Kubernetes versions
36+
37+
The Dapr extension uses the same support window as AKS. For more, see the [Kubernetes version support policy][k8s-version-support-policy].
38+
3539
## Prerequisites
3640

3741
- If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin.
3842
- Install the latest version of the [Azure CLI](/cli/azure/install-azure-cli-windows) and the *aks-preview* extension.
3943
- If you don't have one already, you need to create an [AKS cluster][deploy-cluster].
4044

4145

42-
### Register the `Extensions`, `AKS-ExtensionManager` and `AKS-Dapr` preview features
46+
### Register the `AKS-ExtensionManager` and `AKS-Dapr` preview features
4347

4448
[!INCLUDE [preview features callout](./includes/preview/preview-callout.md)]
4549

46-
To create an AKS cluster that can use the Dapr extension, you must enable the `Extensions`, `AKS-ExtensionManager`, and `AKS-Dapr` feature flags on your subscription.
50+
To create an AKS cluster that can use the Dapr extension, you must enable the `AKS-ExtensionManager` and `AKS-Dapr` feature flags on your subscription.
4751

48-
Register the `Extensions`, `AKS-ExtensionManager`, and `AKS-Dapr` feature flags by using the [az feature register][az-feature-register] command, as shown in the following example:
52+
Register the `AKS-ExtensionManager` and `AKS-Dapr` feature flags by using the [az feature register][az-feature-register] command, as shown in the following example:
4953

5054
```azurecli-interactive
51-
az feature register --namespace "Microsoft.KubernetesConfiguration" --name "Extensions"
5255
az feature register --namespace "Microsoft.ContainerService" --name "AKS-ExtensionManager"
5356
az feature register --namespace "Microsoft.ContainerService" --name "AKS-Dapr"
5457
```
5558

5659
It takes a few minutes for the status to show *Registered*. Verify the registration status by using the [az feature list][az-feature-list] command:
5760

5861
```azurecli-interactive
59-
az feature list -o table --query "[?contains(name, 'Microsoft.KubernetesConfiguration/Extensions')].{Name:name,State:properties.state}"
6062
az feature list -o table --query "[?contains(name, 'Microsoft.ContainerService/AKS-ExtensionManager')].{Name:name,State:properties.state}"
6163
az feature list -o table --query "[?contains(name, 'Microsoft.ContainerService/AKS-Dapr')].{Name:name,State:properties.state}"
6264
```
@@ -168,6 +170,11 @@ az k8s-extension show --cluster-type managedClusters \
168170

169171
## Update configuration settings
170172

173+
> [!IMPORTANT]
174+
> Some configuration options cannot be modified post-creation. Adjustments to these options require deletion and recreation of the extension. This is applicable to the following settings:
175+
> * `global.ha.*`
176+
> * `dapr_placement.*`
177+
171178
> [!NOTE]
172179
> High availability (HA) can be enabled at any time. However, once enabled, disabling it requires deletion and recreation of the extension. If you aren't sure if high availability is necessary for your use case, we recommend starting with it disabled to minimize disruption.
173180

@@ -229,13 +236,15 @@ az k8s-extension delete --resource-group myResourceGroup --cluster-name myAKSClu
229236

230237
## Next Steps
231238

232-
- Once you have successfully provisioned Dapr in your AKS cluster, try deploying a [sample application][sample-application]
239+
- Once you have successfully provisioned Dapr in your AKS cluster, try deploying a [sample application][sample-application].
233240

234241
<!-- LINKS INTERNAL -->
235242
[deploy-cluster]: ./tutorial-kubernetes-deploy-cluster.md
236243
[az-feature-register]: /cli/azure/feature#az_feature_register
237244
[az-feature-list]: /cli/azure/feature#az_feature_list
238245
[az-provider-register]: /cli/azure/provider#az_provider_register
246+
[sample-application]: ./quickstart-dapr.md
247+
[k8s-version-support-policy]: ./supported-kubernetes-versions.md?tabs=azure-cli#kubernetes-version-support-policy
239248

240249
<!-- LINKS EXTERNAL -->
241250
[kubernetes-production]: https://docs.dapr.io/operations/hosting/kubernetes/kubernetes-production

articles/aks/quickstart-dapr.md

Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
---
2+
title: Deploy an application with the Dapr cluster extension (preview) for Azure Kubernetes Service (AKS)
3+
description: Use the Dapr cluster extension (Preview) for Azure Kubernetes Service (AKS) to deploy an application
4+
author: nickomang
5+
ms.author: nickoman
6+
ms.service: container-service
7+
ms.topic: quickstart
8+
ms.date: 11/01/2021
9+
ms.custom: template-quickstart
10+
---
11+
12+
# Quickstart: Deploy an application using the Dapr cluster extension (preview) for Azure Kubernetes Service (AKS)
13+
14+
In this quickstart, you will get familiar with using the [Dapr cluster extension][dapr-overview] 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.
15+
16+
[!INCLUDE [preview features callout](./includes/preview/preview-callout.md)]
17+
18+
## Prerequisites
19+
20+
* An Azure subscription. If you don't have an Azure subscription, you can create a [free account](https://azure.microsoft.com/free).
21+
* [Azure CLI installed](/cli/azure/install-azure-cli).
22+
* An AKS cluster with the [Dapr cluster extension][dapr-overview] enabled
23+
24+
## Clone the repository
25+
26+
To obtain the files you'll be using to deploy the sample application, clone the [Quickstarts repository][hello-world-gh] and change to the `hello-kubernetes` directory:
27+
28+
```bash
29+
git clone https://github.com/dapr/quickstarts.git
30+
cd quickstarts/hello-kubernetes
31+
```
32+
33+
## Create and configure a state store
34+
35+
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.
36+
37+
### Create a Redis store
38+
39+
1. Open the [Azure portal][azure-portal-cache] to start the Azure Redis Cache creation flow.
40+
2. Fill out the necessary information
41+
3. Click “Create” to kickoff deployment of your Redis instance.
42+
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`.
43+
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:
44+
45+
```bash
46+
kubectl create secret generic redis --from-literal=redis-password=<your-redis-password>
47+
```
48+
49+
### Configure the Dapr components
50+
51+
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][dapr-component-secrets].
52+
53+
You will also need to add the following two lines below `redisPassword` to enable connection over TLS:
54+
55+
```yml
56+
- name: redisPassword
57+
secretKeyRef:
58+
name: redis
59+
key: redis-password
60+
- name: enableTLS
61+
value: true
62+
```
63+
64+
### Apply the configuration
65+
66+
Apply the `redis.yaml` file:
67+
68+
```bash
69+
kubectl apply -f ./deploy/redis.yaml
70+
```
71+
72+
And verify that your state store was successfully configured in the output:
73+
74+
```bash
75+
component.dapr.io/statestore created
76+
```
77+
78+
## Deploy the Node.js app with the Dapr sidecar
79+
80+
Apply the Node.js app's deployment to your cluster:
81+
82+
```bash
83+
kubectl apply -f ./deploy/node.yaml
84+
```
85+
86+
> [!NOTE]
87+
> 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:
88+
> ```bash
89+
> kubectl rollout status deploy/nodeapp
90+
> ```
91+
92+
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:
93+
94+
* `dapr.io/enabled: true` - this tells the Dapr control plane to inject a sidecar to this deployment.
95+
96+
* `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.
97+
98+
To access your service, obtain and make note of the `EXTERNAL-IP` via `kubectl`:
99+
100+
```bash
101+
kubectl get svc nodeapp
102+
```
103+
104+
### Verify the service
105+
106+
To call the service, run:
107+
108+
```bash
109+
curl $EXTERNAL_IP/ports
110+
```
111+
112+
You should see output similar to the following:
113+
114+
```bash
115+
{"DAPR_HTTP_PORT":"3500","DAPR_GRPC_PORT":"50001"}
116+
```
117+
118+
Next, submit an order to the application:
119+
120+
```bash
121+
curl --request POST --data "@sample.json" --header Content-Type:application/json $EXTERNAL_IP/neworder
122+
```
123+
124+
Confirm the order has been persisted by requesting it:
125+
126+
```bash
127+
curl $EXTERNAL_IP/order
128+
```
129+
130+
You should see output similar to the following:
131+
132+
```bash
133+
{ "orderId": "42" }
134+
```
135+
136+
> [!TIP]
137+
> 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/`:
138+
> ```bash
139+
> kubectl port-forward svc/dapr-dashboard -n dapr-system 8080:8080
140+
> ```
141+
142+
## Deploy the Python app with the Dapr sidecar
143+
144+
Take a quick look at the Python app. Navigate to the Python app directory in the `hello-kubernetes` quickstart and open `app.py`.
145+
146+
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:
147+
148+
```python
149+
n = 0
150+
while True:
151+
n += 1
152+
message = {"data": {"orderId": n}}
153+
154+
try:
155+
response = requests.post(dapr_url, json=message)
156+
except Exception as e:
157+
print(e)
158+
159+
time.sleep(1)
160+
```
161+
162+
Deploy the Python app to your Kubernetes cluster:
163+
164+
```bash
165+
kubectl apply -f ./deploy/python.yaml
166+
```
167+
168+
> [!NOTE]
169+
> As with above, the following command will wait for the deployment to complete:
170+
> ```bash
171+
> kubectl rollout status deploy/pythonapp
172+
> ```
173+
174+
## Observe messages and confirm persistence
175+
176+
Now that both the Node.js and Python applications are deployed, watch messages come through.
177+
178+
Get the logs of the Node.js app:
179+
180+
```bash
181+
kubectl logs --selector=app=node -c node --tail=-1
182+
```
183+
184+
If the deployments were successful, you should see logs like this:
185+
186+
```bash
187+
Got a new order! Order ID: 1
188+
Successfully persisted state
189+
Got a new order! Order ID: 2
190+
Successfully persisted state
191+
Got a new order! Order ID: 3
192+
Successfully persisted state
193+
```
194+
195+
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!):
196+
197+
```bash
198+
curl $EXTERNAL_IP/order
199+
{"orderID":"42"}
200+
```
201+
202+
You should see the latest JSON in the response.
203+
204+
## Clean up resources
205+
206+
Use the [az group delete][az-group-delete] command to remove the resource group, the AKS cluster, namespace, and all related resources.
207+
208+
```azurecli-interactive
209+
az group delete --name MyResourceGroup
210+
```
211+
212+
## Next steps
213+
214+
After successfully deploying this sample application:
215+
> [!div class="nextstepaction"]
216+
> [Learn more about other cluster extensions][cluster-extensions]
217+
218+
<!-- LINKS -->
219+
<!-- INTERNAL -->
220+
[cluster-extensions]: ./cluster-extensions.md
221+
[dapr-overview]: ./dapr.md
222+
[az-group-delete]: /cli/azure/group#az_group_delete
223+
224+
<!-- EXTERNAL -->
225+
[hello-world-gh]: https://github.com/dapr/quickstarts/tree/v1.4.0/hello-kubernetes
226+
[azure-portal-cache]: https://ms.portal.azure.com/#create/Microsoft.Cache
227+
[dapr-component-secrets]: https://docs.dapr.io/operations/components/component-secrets/

0 commit comments

Comments
 (0)