Skip to content

Commit ce62f12

Browse files
committed
initial commit for dapr refactor
Signed-off-by: Ryan Winter <[email protected]>
1 parent 819c15c commit ce62f12

File tree

4 files changed

+207
-164
lines changed

4 files changed

+207
-164
lines changed

articles/iot-operations/develop/howto-develop-dapr-apps.md

Lines changed: 19 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -24,148 +24,10 @@ The Distributed Application Runtime (Dapr) is a portable, serverless, event-driv
2424

2525
To use Dapr pluggable components, define all the components, then add pluggable component containers to your [deployments](https://docs.dapr.io/operations/components/pluggable-components-registration/). The Dapr component listens to a Unix Domain Socket placed on the shared volume, and Dapr runtime connects with each socket and discovers all services from a given building block API that the component implements. Each deployment must have its own pluggable component defined. This guide shows you how to deploy an application using the Dapr SDK and IoT MQ pluggable components.
2626

27-
## Install Dapr runtime
27+
## Prerequisites
2828

29-
To install the Dapr runtime, use the following Helm command. If you completed the provided Azure IoT Operations Preview [quickstart](../get-started/quickstart-deploy.md), you already installed the runtime.
30-
31-
```bash
32-
helm repo add dapr https://dapr.github.io/helm-charts/
33-
helm repo update
34-
helm upgrade --install dapr dapr/dapr --version=1.11 --namespace dapr-system --create-namespace --wait
35-
```
36-
37-
> [!IMPORTANT]
38-
> **Dapr v1.12** is currently not supported.
39-
40-
## Register MQ's pluggable components
41-
42-
To register MQ's pluggable Pub/sub and State Management components, create the component manifest yaml, and apply it to your cluster.
43-
44-
To create the yaml file, use the following component definitions:
45-
46-
> [!div class="mx-tdBreakAll"]
47-
> | Component | Description |
48-
> |-|-|
49-
> | `metadata.name` | The component name is important and is how a Dapr application references the component. |
50-
> | `spec.type` | [The type of the component](https://docs.dapr.io/operations/components/pluggable-components-registration/#define-the-component), which must be declared exactly as shown. It tells Dapr what kind of component (`pubsub` or `state`) it is and which Unix socket to use. |
51-
> | `spec.metadata.url` | The URL tells the component where the local MQ endpoint is. Defaults to `8883` is MQ's default MQTT port with TLS enabled. |
52-
> | `spec.metadata.satTokenPath` | The Service Account Token is used to authenticate the Dapr components with the MQTT broker |
53-
> | `spec.metadata.tlsEnabled` | Define if TLS is used by the MQTT broker. Defaults to `true` |
54-
> | `spec.metadata.caCertPath` | The certificate chain path for validating the broker, required if `tlsEnabled` is `true` |
55-
> | `spec.metadata.logLevel` | The logging level of the component. 'Debug', 'Info', 'Warn' and 'Error' |
56-
57-
1. Save the following yaml, which contains the component definitions, to a file named `components.yaml`:
58-
59-
```yml
60-
# Pub/sub component
61-
apiVersion: dapr.io/v1alpha1
62-
kind: Component
63-
metadata:
64-
name: aio-mq-pubsub
65-
namespace: azure-iot-operations
66-
spec:
67-
type: pubsub.aio-mq-pubsub-pluggable # DO NOT CHANGE
68-
version: v1
69-
metadata:
70-
- name: url
71-
value: "aio-mq-dmqtt-frontend:8883"
72-
- name: satTokenPath
73-
value: "/var/run/secrets/tokens/mqtt-client-token"
74-
- name: tlsEnabled
75-
value: true
76-
- name: caCertPath
77-
value: "/var/run/certs/aio-mq-ca-cert/ca.crt"
78-
- name: logLevel
79-
value: "Info"
80-
---
81-
# State Management component
82-
apiVersion: dapr.io/v1alpha1
83-
kind: Component
84-
metadata:
85-
name: aio-mq-statestore
86-
namespace: azure-iot-operations
87-
spec:
88-
type: state.aio-mq-statestore-pluggable # DO NOT CHANGE
89-
version: v1
90-
metadata:
91-
- name: url
92-
value: "aio-mq-dmqtt-frontend:8883"
93-
- name: satTokenPath
94-
value: "/var/run/secrets/tokens/mqtt-client-token"
95-
- name: tlsEnabled
96-
value: true
97-
- name: caCertPath
98-
value: "/var/run/certs/aio-mq-ca-cert/ca.crt"
99-
- name: logLevel
100-
value: "Info"
101-
```
102-
103-
1. Apply the component yaml to your cluster by running the following command:
104-
105-
```bash
106-
kubectl apply -f components.yaml
107-
```
108-
109-
Verify the following output:
110-
111-
```output
112-
component.dapr.io/aio-mq-pubsub created
113-
component.dapr.io/aio-mq-statestore created
114-
```
115-
116-
## Set up authorization policy between the application and MQ
117-
118-
To configure authorization policies to Azure IoT MQ, first you create a [BrokerAuthorization resource](../manage-mqtt-connectivity/howto-configure-authorization.md).
119-
120-
> [!NOTE]
121-
> If Broker Authorization is not enabled on this cluster, you can skip this section as the applications will have access to all MQTT topics.
122-
123-
1. Annotate the service account `mqtt-client` with an [authorization attribute](../manage-mqtt-connectivity/howto-configure-authentication.md#create-a-service-account):
124-
125-
```bash
126-
kubectl annotate serviceaccount mqtt-client aio-mq-broker-auth/group=dapr-workload -n azure-iot-operations
127-
```
128-
129-
1. Save the following yaml, which contains the BrokerAuthorization definition, to a file named `aio-mq-authz.yaml`.
130-
131-
Use the following definitions:
132-
133-
> [!div class="mx-tdBreakAll"]
134-
> | Item | Description |
135-
> |-|-|
136-
> | `dapr-workload` | The Dapr application authorization attribute assigned to the service account |
137-
> | `topics` | Describe the topics required to communicate with the MQ State Store |
138-
139-
```yml
140-
apiVersion: mq.iotoperations.azure.com/v1beta1
141-
kind: BrokerAuthorization
142-
metadata:
143-
name: my-authz-policies
144-
namespace: azure-iot-operations
145-
spec:
146-
listenerRef:
147-
- my-listener # change to match your listener name as needed
148-
authorizationPolicies:
149-
enableCache: false
150-
rules:
151-
- principals:
152-
attributes:
153-
- group: dapr-workload
154-
brokerResources:
155-
- method: Connect
156-
- method: Publish
157-
topics:
158-
- "$services/statestore/#"
159-
- method: Subscribe
160-
topics:
161-
- "clients/{principal.clientId}/services/statestore/#"
162-
```
163-
164-
1. Apply the BrokerAuthorizaion definition to the cluster:
165-
166-
```bash
167-
kubectl apply -f aio-mq-authz.yaml
168-
```
29+
* Azure IoT Operations deployed - [Deploy Azure IoT Operations](../get-started/quickstart-deploy.md)
30+
* IoT MQ Dapr Components deployed - [Deploy IoT MQ Dapr Components](./howto-develop-deploy-dapr.md)
16931

17032
## Creating a Dapr application
17133

@@ -194,11 +56,9 @@ After you finish writing the Dapr application, build the container:
19456

19557
## Deploy a Dapr application
19658

197-
To deploy the Dapr application to your cluster, you can use either a Kubernetes [Pod](https://kubernetes.io/docs/concepts/workloads/pods/) or [Deployment](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/)
198-
199-
The following Pod definition defines the different volumes required to deploy the application along with the required containers.
59+
The following [Deployment](https://kubernetes.io/docs/concepts/workloads/controllers/deployment/) definition defines the different volumes required to deploy the application along with the required containers.
20060

201-
To start, you create a yaml file that uses the following definitions:
61+
To start, create a yaml file with the following definitions:
20262

20363
> | Component | Description |
20464
> |-|-|
@@ -210,6 +70,14 @@ To start, you create a yaml file that uses the following definitions:
21070
1. Save the following yaml to a file named `dapr-app.yaml`:
21171

21272
```yml
73+
apiVersion: v1
74+
kind: ServiceAccount
75+
metadata:
76+
name: dapr-client
77+
namespace: azure-iot-operations
78+
annotations:
79+
aio-mq-broker-auth/group: dapr-workload
80+
---
21381
apiVersion: apps/v1
21482
kind: Deployment
21583
metadata:
@@ -231,6 +99,8 @@ To start, you create a yaml file that uses the following definitions:
23199
dapr.io/app-port: "6001"
232100
dapr.io/app-protocol: "grpc"
233101
spec:
102+
serviceAccountName: dapr-client
103+
234104
volumes:
235105
- name: dapr-unix-domain-socket
236106
emptyDir: {}
@@ -250,11 +120,11 @@ To start, you create a yaml file that uses the following definitions:
250120
name: aio-ca-trust-bundle-test-only
251121
252122
containers:
253-
# Container for the dapr quickstart application
123+
# Container for the Dapr application
254124
- name: mq-dapr-app
255-
image: <YOUR DAPR APPLICATION>
125+
image: <YOUR_DAPR_APPLICATION>
256126
257-
# Container for the Pub/sub component
127+
# Container for the Dapr Pub/sub component
258128
- name: aio-mq-pubsub-pluggable
259129
image: ghcr.io/azure/iot-mq-dapr-components/pubsub:latest
260130
volumeMounts:
@@ -265,7 +135,7 @@ To start, you create a yaml file that uses the following definitions:
265135
- name: aio-ca-trust-bundle
266136
mountPath: /var/run/certs/aio-mq-ca-cert/
267137
268-
# Container for the State Management component
138+
# Container for the Dapr State store component
269139
- name: aio-mq-statestore-pluggable
270140
image: ghcr.io/azure/iot-mq-dapr-components/statestore:latest
271141
volumeMounts:
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
---
2+
title: Deploy Dapr Pluggable Components
3+
titleSuffix: Azure IoT MQ
4+
description: Deploy Dapr and the IoT MQ Pluggable Components to a cluster.
5+
author: timlt
6+
ms.author: timlt
7+
ms.subservice: mq
8+
ms.topic: how-to
9+
ms.custom:
10+
ms.date: 1/31/2024
11+
---
12+
13+
# Deploy Dapr Pluggable Components
14+
15+
[!INCLUDE [public-preview-note](../includes/public-preview-note.md)]
16+
17+
The Distributed Application Runtime (Dapr) is a portable, serverless, event-driven runtime that simplifies the process of building distributed application. Dapr enables developers to build stateful or stateless apps without worrying about how the building blocks function. Dapr provides several [building blocks](https://docs.dapr.io/developing-applications/building-blocks/): pub/sub, state management, service invocation, actors, and more.
18+
19+
Azure IoT MQ Preview supports two of these building blocks, powered by [Azure IoT MQ MQTT broker](../manage-mqtt-connectivity/overview-iot-mq.md):
20+
21+
- Pub/sub
22+
- State Management
23+
24+
To use Dapr pluggable components, register the components, then add the pluggable component containers to your [deployments](https://docs.dapr.io/operations/components/pluggable-components-registration/). The Dapr component listens to a Unix Domain Socket placed on the shared volume, and Dapr runtime connects with each socket and discovers all services from a given building block API that the component implements.
25+
26+
This guide shows you how to deploy an application using the Dapr SDK and IoT MQ pluggable components.
27+
28+
## Install Dapr runtime
29+
30+
To install the Dapr runtime, use the following Helm command:
31+
32+
> [!NOTE]
33+
> If you completed the provided Azure IoT Operations Preview [quickstart](../get-started/quickstart-deploy.md), you already installed the Dapr runtime and the following steps are not required.
34+
35+
```bash
36+
helm repo add dapr https://dapr.github.io/helm-charts/
37+
helm repo update
38+
helm upgrade --install dapr dapr/dapr --version=1.11 --namespace dapr-system --create-namespace --wait
39+
```
40+
41+
> [!IMPORTANT]
42+
> **Dapr v1.12** is currently not supported.
43+
44+
## Register MQ's pluggable components
45+
46+
To register MQ's pluggable Pub/sub and State Management components, create the component manifest yaml, and apply it to your cluster.
47+
48+
To create the yaml file, use the following component definitions:
49+
50+
> [!div class="mx-tdBreakAll"]
51+
> | Component | Description |
52+
> |-|-|
53+
> | `metadata.name` | The component name is important and is how a Dapr application references the component. |
54+
> | `spec.type` | [The type of the component](https://docs.dapr.io/operations/components/pluggable-components-registration/#define-the-component), which must be declared exactly as shown. It tells Dapr what kind of component (`pubsub` or `state`) it is and which Unix socket to use. |
55+
> | `spec.metadata.url` | The URL tells the component where the local MQ endpoint is. Defaults to `8883` is MQ's default MQTT port with TLS enabled. |
56+
> | `spec.metadata.satTokenPath` | The Service Account Token is used to authenticate the Dapr components with the MQTT broker |
57+
> | `spec.metadata.tlsEnabled` | Define if TLS is used by the MQTT broker. Defaults to `true` |
58+
> | `spec.metadata.caCertPath` | The certificate chain path for validating the broker, required if `tlsEnabled` is `true` |
59+
> | `spec.metadata.logLevel` | The logging level of the component. 'Debug', 'Info', 'Warn' and 'Error' |
60+
61+
1. Save the following yaml, which contains the component definitions, to a file named `components.yaml`:
62+
63+
```yml
64+
# Pub/sub component
65+
apiVersion: dapr.io/v1alpha1
66+
kind: Component
67+
metadata:
68+
name: aio-mq-pubsub
69+
namespace: azure-iot-operations
70+
spec:
71+
type: pubsub.aio-mq-pubsub-pluggable # DO NOT CHANGE
72+
version: v1
73+
metadata:
74+
- name: url
75+
value: "aio-mq-dmqtt-frontend:8883"
76+
- name: satTokenPath
77+
value: "/var/run/secrets/tokens/mqtt-client-token"
78+
- name: tlsEnabled
79+
value: true
80+
- name: caCertPath
81+
value: "/var/run/certs/aio-mq-ca-cert/ca.crt"
82+
- name: logLevel
83+
value: "Info"
84+
---
85+
# State Management component
86+
apiVersion: dapr.io/v1alpha1
87+
kind: Component
88+
metadata:
89+
name: aio-mq-statestore
90+
namespace: azure-iot-operations
91+
spec:
92+
type: state.aio-mq-statestore-pluggable # DO NOT CHANGE
93+
version: v1
94+
metadata:
95+
- name: url
96+
value: "aio-mq-dmqtt-frontend:8883"
97+
- name: satTokenPath
98+
value: "/var/run/secrets/tokens/mqtt-client-token"
99+
- name: tlsEnabled
100+
value: true
101+
- name: caCertPath
102+
value: "/var/run/certs/aio-mq-ca-cert/ca.crt"
103+
- name: logLevel
104+
value: "Info"
105+
```
106+
107+
1. Apply the component yaml to your cluster by running the following command:
108+
109+
```bash
110+
kubectl apply -f components.yaml
111+
```
112+
113+
Verify the following output:
114+
115+
```output
116+
component.dapr.io/aio-mq-pubsub created
117+
component.dapr.io/aio-mq-statestore created
118+
```
119+
120+
## Create authorization policy for IoT MQ
121+
122+
To configure authorization policies to Azure IoT MQ, first you create a [BrokerAuthorization](../manage-mqtt-connectivity/howto-configure-authorization.md) resource.
123+
124+
> [!NOTE]
125+
> If Broker Authorization is not enabled on this cluster, you can skip this section as the applications will have access to all MQTT topics, including those needed to access the IoT MQ State Store.
126+
127+
1. Save the following yaml, which contains a BrokerAuthorization definition, to a file named `aio-dapr-authz.yaml`:
128+
129+
```yml
130+
apiVersion: mq.iotoperations.azure.com/v1beta1
131+
kind: BrokerAuthorization
132+
metadata:
133+
name: my-dapr-authz-policies
134+
namespace: azure-iot-operations
135+
spec:
136+
listenerRef:
137+
- my-listener # change to match your listener name as needed
138+
authorizationPolicies:
139+
enableCache: false
140+
rules:
141+
- principals:
142+
attributes:
143+
- group: dapr-workload # match to the attribute annotated to the service account
144+
brokerResources:
145+
- method: Connect
146+
- method: Publish
147+
topics:
148+
- "$services/statestore/#"
149+
- method: Subscribe
150+
topics:
151+
- "clients/{principal.clientId}/services/statestore/#"
152+
```
153+
154+
1. Apply the BrokerAuthorizaion definition to the cluster:
155+
156+
```bash
157+
kubectl apply -f aio-dapr-authz.yaml
158+
```
159+
160+
## Related content
161+
162+
-

0 commit comments

Comments
 (0)