How-To: Connect to dependencies
Categories:
This how-to guide will teach how to connect to your dependencies via connections
Prerequisites
Step 1: View the container definition
Open the app.bicep
and view the container:
extension radius
@description('The app ID of your Radius application. Set automatically 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'
ports: {
web: {
containerPort: 3000
}
}
}
}
}
Step 2: Add a Redis cache as a dependency
Next, add to app.bicep
a Redis cache, leveraging the default “local-dev” Recipe:
@description('The env ID of your Radius Environment. Set automatically by the rad CLI.')
param environment string
resource db 'Applications.Datastores/redisCaches@2023-10-01-preview' = {
name: 'db'
properties: {
application: application
environment: environment
}
}
Step 3: Connect to the Redis cache
Connections from a container to a resource result in environment variables for connection information automatically being set on the container. Update your container definition to add a connection to the new Redis cache:
|
|
Step 4: Deploy your app
-
Run your application in your environment:
rad run ./app.bicep -a demo
-
Visit localhost:3000 in your browser. You should see the following page, now showing injected environment variables:
Step 5: View the Application Connections
Radius Connections are more than just environment variables and configuration. You can also access the “application graph” and understand the connections within your application with the following command:
rad app graph -a demo
You should see the following output, detailing the connections between the demo
container and the db
Redis cache, along with information about the underlying Kubernetes resources running the app:
Displaying application: demo
Name: demo (Applications.Core/containers)
Connections:
demo -> db (Applications.Datastores/redisCaches)
Resources:
demo (kubernetes: apps/Deployment)
demo (kubernetes: core/Secret)
demo (kubernetes: core/Service)
demo (kubernetes: core/ServiceAccount)
demo (kubernetes: rbac.authorization.k8s.io/Role)
demo (kubernetes: rbac.authorization.k8s.io/RoleBinding)
Name: db (Applications.Datastores/redisCaches)
Connections:
demo (Applications.Core/containers) -> db
Resources:
redis-r5tcrra3d7uh6 (kubernetes: apps/Deployment)
redis-r5tcrra3d7uh6 (kubernetes: core/Service)
Cleanup
Run rad app delete
to cleanup your Radius application, container, and Redis cache:
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.