Skip to content

Commit

Permalink
Adding a Dapr sidecar how-to (#937)
Browse files Browse the repository at this point in the history
* Adding a Dapr sidecar how-to

Signed-off-by: jasonviviano <[email protected]>

* Added the steps to deploy the app with the sidecar to the docs based on the tutorial guide.

Signed-off-by: jasonviviano <[email protected]>

* Fixed link

Signed-off-by: jasonviviano <[email protected]>

* Apply suggestions from code review

Co-authored-by: Aaron Crawfis <[email protected]>
Signed-off-by: jasonviviano <[email protected]>

* Apply suggestions from code review

Co-authored-by: Aaron Crawfis <[email protected]>
Signed-off-by: jasonviviano <[email protected]>

* Added a prereq to the Dapr sidecar guide

Signed-off-by: jasonviviano <[email protected]>

* Added console output for dapr sidecar check.

Signed-off-by: jasonviviano <[email protected]>

* Fix formatting

Signed-off-by: Aaron Crawfis <[email protected]>

---------

Signed-off-by: jasonviviano <[email protected]>
Signed-off-by: Aaron Crawfis <[email protected]>
Co-authored-by: Aaron Crawfis <[email protected]>
  • Loading branch information
jasonviviano and AaronCrawfis authored Dec 1, 2023
1 parent f18a9d4 commit 9ea142a
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 0 deletions.
88 changes: 88 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,88 @@
---
type: docs
title: "How-To: Add a Dapr sidecar to a container"
linkTitle: "Add a Dapr sidecar"
description: "Learn how to add a Dapr sidecar to a Radius container"
weight: 200
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

- [Supported Kubernetes cluster]({{< ref "/guides/operations/kubernetes/overview#supported-kubernetes-clusters" >}})
- [rad CLI]({{< ref getting-started >}})
- [Dapr CLI](https://docs.dapr.io/getting-started/install-dapr-cli/)
- [Radius initialized with `rad init`]({{< ref howto-environment >}})
- [Dapr initialized with `dapr init -k`](https://docs.dapr.io/getting-started/install-dapr-selfhost/)

## Step 1: Start with 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: Add a Dapr sidecar extension

Now add the Dapr sidecar extension, which enabled Dapr and adds a Dapr sidecar:

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

## Step 3: Deploy the app

Deploy your application:

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

Your console output should look similar to:

```
Building ./app.bicep...
Deploying template './app.bicep' for application 'demo' and environment 'default' from workspace 'default'...
Deployment In Progress...
... demo Applications.Core/containers
Deployment Complete
Resources:
demo Applications.Core/containers
```

## Step 4: Verify the Dapr sidecar

Run `dapr list -k` to list all Dapr pods in your Kubernetes cluster:

```bash
dapr list -k
```


The console output should look similar to:

```
NAMESPACE APP ID APP PORT AGE CREATED
default-demo demo 3000 29s 2023-11-30 21:52.59
```

## Done

You've successfully deployed a Radius container with a Dapr sidecar! You can now interact with Dapr building blocks and the Dapr API from your container.


## Cleanup

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

```bash
rad app delete -a demo
```

## Further reading

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

@description('The ID of your Radius Application. Automatically injected by the rad CLI.')
param application string

//CONTAINER
resource demo 'Applications.Core/containers@2023-10-01-preview' = {
name: 'demo'
properties: {
application: application
container: {
image: 'ghcr.io/radius-project/samples/demo:latest'
}
extensions: [
{
kind: 'daprSidecar'
appId: 'demo'
appPort: 3000
}
]
}
}
//CONTAINER
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import radius as radius

@description('The ID of your Radius Application. Automatically injected by the rad CLI.')
param application string

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

0 comments on commit 9ea142a

Please sign in to comment.