How-To: Add a Dapr sidecar to a container
Categories:
This how-to guide will provide an overview of how to:
- Leverage a Dapr sidecar with your Radius Application
Prerequisites
- Supported Kubernetes cluster
- rad CLI
- Dapr CLI
- Radius initialized with
rad init
- Dapr initialized with
dapr init -k
Step 1: Start with a container
Begin by creating a file named app.bicep
with a Radius container:
extension 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'
}
}
}
Step 2: Add a Dapr sidecar extension
Now add the Dapr sidecar extension, which enabled Dapr and adds a Dapr sidecar:
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
}
]
}
}
Step 3: Deploy the app
Deploy your application:
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:
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 your app and container:
rad app delete -a demo
Further reading
Feedback
Was this page helpful?
Glad to hear it! Please feel free to star our repo and join our Discord server to stay up to date with the project.
Sorry to hear that. If you would like to also contribute a suggestion visit and tell us how we can improve.