Skip to content

Commit

Permalink
Adding a Dapr sidecar how-to
Browse files Browse the repository at this point in the history
Signed-off-by: jasonviviano <[email protected]>
  • Loading branch information
jasonviviano committed Nov 13, 2023
1 parent 55fb874 commit c3b6de8
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 0 deletions.
59 changes: 59 additions & 0 deletions docs/content/guides/author-apps/dapr/how-to-dapr-sidecar/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
---
type: docs
title: "How-To: Add a Dapr sidecar to Radius"
linkTitle: "Add a Dapr sidecar to Radius"
description: "Easily leverage a Dapr sidecar blocks in your application for code and infrastructure portability"
weight: 100
categories: "How-To"
tags: ["Dapr"]
---

This how-to guide will provide an overview of how to:

- Leverage a [Dapr sidecar](https://docs.dapr.io/concepts/dapr-services/sidecar/) with your Radius Application

## Prerequisites

- [rad CLI]({{< ref getting-started >}})
- [Radius initialized with `rad init`]({{< ref howto-environment >}})
- [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/)
- [Dapr](https://docs.dapr.io/getting-started/install-dapr-cli/)

## Step 1: Define a container

Begin by creating a file named `app.bicep` with a Radius [container]({{< ref "guides/author-apps/containers" >}}):

{{< rad file="snippets/app.bicep" embed=true >}}

## Step 2: Define the Dapr sidecar extension

Make sure your current Dapr sidecar process is running inside a Kubernetes cluster:

```
daprd --app-id myapp
```

You'll need the following information `appId`, `appPort` and any additional `config` properties can be defined inside of your Radius container definition.

{{< rad file="snippets/app-sidecar.bicep" embed=true >}}

## Step 3: Deploy the Radius Application

1. Deploy and run your app:

```bash
rad run ./app.bicep -a demo
```

## Cleanup

Run the following command to [delete]({{< ref "guides/deploy-apps/howto-delete" >}}) your app and container:

```bash
rad app delete demo
```

## Further reading

- [Dapr in Radius containers]({{< ref "guides/author-apps/containers/overview#kubernetes" >}})
- [Dapr sidecar schema]({{< ref "reference/resource-schema/dapr-schema/extension/" >}})
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import radius as radius

@description('Specifies the environment for resources.')
param environment string

resource app 'Applications.Core/applications@2023-10-01-preview' = {
name: 'demo'
properties: {
environment: environment
}
}

resource demo 'Applications.Core/containers@2023-10-01-preview' = {
name: 'demo'
properties: {
application: app.id
container: {...}
extensions: [
{
kind: 'daprSidecar'
appId: 'demo'
appPort: 3000
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import radius as radius

@description('Specifies the environment for resources.')
param environment string

resource app 'Applications.Core/applications@2023-10-01-preview' = {
name: 'demo'
properties: {
environment: environment
}
}

resource demo 'Applications.Core/containers@2023-10-01-preview' = {
name: 'demo'
properties: {
application: app.id
container: {
image: 'ghcr.io/radius-project/samples/demo:latest'
ports: {
web: {
containerPort: 3000
}
}
}
}
}

0 comments on commit c3b6de8

Please sign in to comment.