Skip to content

Commit

Permalink
Merge branch 'v0.31' into jasonviviano/kubernetes-resource
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonviviano authored Mar 11, 2024
2 parents eb31f56 + c9c773c commit c44a72c
Show file tree
Hide file tree
Showing 8 changed files with 218 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Refer to the probes section of the [container resource schema]({{< ref "containe

## Connections

When a connection between two resources is declared, Radius injects resource related information into environment variables that are then used to access the respective resource without having to hard code URIs, connection strings, access keys, or anything that application code needs to successfully communicate.
When a connection is declared from a container to another Radius resource, Radius injects environment variables with connection information to make it easy to access the target resource. These variables can be used by your code to access the resource without manually hard-coding or mounting URIs, connection strings, access keys, or other values. Connection information is securely managed by the Radius Environment, ensuring it is stored and mounted correctly.

These environment variables follow a naming convention that makes their use predictable. The naming pattern is derived from the connection name and resource type, which determines what values are required. This way the code that needs to read the values gets to define how they are named. Refer to the [reference documentation]({{< ref resource-schema >}}) of each resource for more information.

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
---
type: docs
title: "How-To: Add a Dapr building block"
linkTitle: "Add a building block"
description: "Learn how to add a Dapr building block to a Radius Application"
weight: 300
categories: "How-To"
tags: ["Dapr"]
---

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

- Leverage a [Dapr building block](https://docs.dapr.io/developing-applications/building-blocks/) in your Radius Application

## Prerequisites

- [rad CLI]({{< ref "installation#step-1-install-the-rad-cli" >}})
- [Radius Bicep VSCode extension]({{< ref "installation#step-2-install-the-vs-code-extension" >}})
- [Radius environment]({{< ref "installation#step-3-initialize-radius" >}})
- [Radius local-dev Recipes]({{< ref howto-dev-recipes >}})
- [Dapr installed on your Kubernetes cluster](https://docs.dapr.io/operations/hosting/kubernetes/kubernetes-deploy/)

## Step 1: Start with a container and a Dapr sidecar

Begin by creating a file named `app.bicep` with a defined Radius container and a Dapr sidecar, if you need a in-depth walkthrough see the ['How-To: Add a Dapr sidecar to a container' guide]({{< ref how-to-dapr-sidecar >}}):

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

## Step 2: Add a Dapr state store resource

Now add a Dapr state store resource, which models a [Dapr state store component](https://docs.dapr.io/developing-applications/building-blocks/state-management/state-management-overview/). The underlying infrastructure and Dapr component configuration are deployed via a [`local-dev` Recipe]({{< ref "guides/recipes/overview##use-lightweight-local-dev-recipes" >}}), which leverages a lightweight Redis container:

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

> Visit the [Radius Recipe repo](https://github.com/radius-project/recipes/blob/main/local-dev/statestores.bicep) to learn more about `local-dev` Recipes and view the Dapr State Store Recipe used in this guide.
## Step 3: Add a connection from the container resource to the Dapr state store resource

Update your container resource with a connection to the Dapr state store. This will inject important connection information (the component name) into the container's environment variables:

{{< rad file="./snippets/app-statestore.bicep" embed=true marker="//CONTAINER" >}}
## Step 3: Deploy the application

Run your application with the `rad` CLI:

```bash
rad run ./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...
Completed statestore Applications.Dapr/stateStores
... demo Applications.Core/containers
Deployment Complete
Resources:
demo Applications.Core/containers
statestore Applications.Dapr/stateStores
Starting log stream...
```

Open [http://localhost:3000](http://localhost:3000) to view the Radius demo container. Which should contain the following connection information:

{{< image src="app-statestore.png" alt="Screenshot of the demo Redis connection" width=700px >}}
## Step 4: Verify the Dapr statestore

Run the command below to see all the pods running in your Kubernetes cluster:

```bash
dapr components --namespace "default-demo" -k
```

The console output should similar to:

```
NAMESPACE NAME TYPE VERSION SCOPES CREATED AGE
default-demo statestore state.redis v1 2024-02-19 17:13.20 2m
```

## Done

You've successfully deployed a Radius container with a Dapr sidecar along with a Dapr State Store. With the combination of Radius + Dapr, both your application's code and it's definition are now platform neutral.

## Cleanup

To delete your app, run the [rad app delete]({{< ref rad_application_delete >}}) command to cleanup the app and its resources, including the Recipe resources:

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

## Further reading

- [Dapr building blocks](https://docs.dapr.io/concepts/building-blocks-concept/)
- [Dapr resource schemas]({{< ref dapr-schema >}})

Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import radius as radius

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

@description('The ID of your Radius environment. Automatically injected by the rad CLI.')
param environment 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
}
}
}
extensions: [
{
kind: 'daprSidecar'
appId: 'demo'
appPort: 3000
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import radius as radius

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

@description('The ID of your Radius environment. Automatically injected by the rad CLI.')
param environment 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'
ports: {
web: {
containerPort: 3000
}
}
}
extensions: [
{
kind: 'daprSidecar'
appId: 'demo'
appPort: 3000
}
]
connections: {
redis: {
source: stateStore.id
}
}
}
}
//CONTAINER

//STATESTORE
resource stateStore 'Applications.Dapr/stateStores@2023-10-01-preview' = {
name: 'statestore'
properties: {
environment: environment
application: application
}
}
//STATESTORE
5 changes: 3 additions & 2 deletions docs/content/guides/operations/kubernetes/overview/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ Kubernetes version `1.23.8` or higher is recommended to run Radius.

Radius resources, when deployed to a Kubernetes environment, are mapped to one or more Kubernetes objects. The following table describes the mapping between Radius resources and Kubernetes objects:

| Radius resource | Kubernetes object |
| Radius resource/configuration | Kubernetes object |
|----------------------------------|-------------------|
| [`Applications.Core/containers`]({{< ref container-schema >}}) | `apps/Deployment@v1`<br />`core/Service@v1` _(if ports defined)_ |
| [`Applications.Core/containers`]({{< ref container-schema >}}) | `apps/Deployment@v1`<br /> <br /> `core/Service@v1` _(if ports defined)_ |
| `Applications.Core/containers` connections | `core/Secret@v1` <br /> Mounted to the container as environment variables. Refer to the [connections guide]({{< ref howto-connect-dependencies >}}) to learn more. |
| [`Applications.Core/gateways`]({{< ref gateway >}}) | `projectcontour.io/HTTPProxy@v1` |
| [`Applications.Dapr/pubSubBrokers`]({{< ref dapr-pubsub >}}) | `dapr.io/Component@v1alpha1` |
| [`Applications.Dapr/secretStores`]({{< ref dapr-secretstore >}}) | `dapr.io/Component@v1alpha1` |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ weight: 000
| Key | Required | Description | Example |
|------|:--------:|-------------|---------|
| [compute](#compute) | y | Container runtime configuration. | [See below](#compute)
| [recipeConfig](#recipeconfig) | n | Configuration for Recipes. Defines how each type of Recipe should be configured and run. | [See below](#recipeconfig)
| [recipes](#recipes) | n | Recipes registered to the environment | [See below](#recipes)
| simulated | n | When enabled, a simulated environment will not deploy any output resources or run any Recipes when an application is deployed. This is useful for dry runs or testing. Defaults to `false`. | `true`
| [extensions](#extensions) | n | The environment extension. | [See below](#extensions)

### compute

Expand All @@ -44,6 +46,38 @@ Details on what to run and how to run it are defined in the `container` property
| kind | y | The kind of identity. 'azure.com.workload' is currently only supported. | `'azure.com.workload'` |
| oidcIssuer | n | The [OIDC issuer URL](https://azure.github.io/azure-workload-identity/docs/installation/self-managed-clusters/oidc-issuer.html) for your Kubernetes cluster. | `'{IssuerURL}/.well-known/openid-configuration'` |

### recipeConfig

| Key | Required | Description | Example |
|------|:--------:|-------------|---------|
| terraform | y | Configuration for Terraform Recipes. Controls how Terraform plans and applies templates as part of Recipe deployment. | [See below](#terraform-properties)
| env | n | Environment variables injected during Terraform Recipe execution for the recipes in the environment. | [See below](#env-properties)

#### terraform properties

| Key | Required | Description | Example |
|------|:--------:|-------------|---------|
| authentication | y | Authentication information used to access private Terraform module sources. Supported module sources: Git. | [See below](#authentication-properties)
| providers | n | Configuration for Terraform Recipe Providers. Controls how Terraform interacts with cloud providers, SaaS providers, and other APIs. | For more information refer to the [Terraform documentation](https://developer.hashicorp.com/terraform/language/providers/configuration).

##### authentication properties

| Key | Required | Description | Example |
|------|:--------:|-------------|---------|
| pat | y | Personal Access Token (PAT) configuration used to authenticate to Git platforms. | [See below](#pat-properties)

##### pat properties

| Key | Required | Description | Example |
|------|:--------:|-------------|---------|
| secret | y | The ID of an Applications.Core/SecretStore resource containing the Git platform personal access token (PAT). The secret store must have a secret named 'pat', containing the PAT value. A secret named 'username' is optional, containing the username associated with the pat. By default no username is specified. | For more information refer to the [Terraform documentation](https://developer.hashicorp.com/terraform/language/providers/configuration).

#### env properties

| Key | Required | Description | Example |
|------|:--------:|-------------|---------|
| \<user-defined key-value pairs\> | n | User-defined environment variables. | `'env_var_1'`: `'env_value_1'`

### recipes

| Key | Required | Description | Example |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Note that only Kubernetes Secrets are currently supported with more to come in t

| Key | Required | Description | Example |
|----------|:--------:|-------------|---------|
| application | y | The ID of the application resource this resource belongs to. | `app.id` |
| application | n | The ID of the application resource this resource belongs to. | `app.id` |
| resource | n | Reference to the backing secret store resource, required only if valueFrom specifies referenced secret name. | `namespace/secretName` |
| type | y | The type of secret in your resource. | `'certificate'`
| [data](#data) | y | An object to represent key-value type secrets. | [See below](#data)
Expand Down

0 comments on commit c44a72c

Please sign in to comment.