You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 2cfa299
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: docs/content/getting-started/add-connection/_index.md
+22-19Lines changed: 22 additions & 19 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,54 +6,57 @@ description: "Add a PostgreSQL database and connect the Radius Demo container to
6
6
weight: 300
7
7
---
8
8
9
-
The Radius Demo application runs on its own, but most applications depend on other resources such as databases and caches. In this step you will add a PostgreSQL database to the application and create a *connection* from the container to it.
9
+
The Radius Demo application runs on its own, but most applications depend on other resources such as databases and caches. In this step you will add a PostgreSQL database and an authored Secret to the application, then connect the container to both resources.
10
10
11
-
## Add a PostgreSQL database and connection
11
+
## Add a PostgreSQL database and connections
12
12
13
-
The `app-postgresql.bicep` definition builds on `app.bicep` by adding a `Radius.Data/postgreSqlDatabases` resource, a `@secure()` password parameter, and a`connections`entry on the container. The highlighted lines are the additions:
13
+
The `app-postgresql.bicep` definition builds on `app.bicep` by adding a `Radius.Data/postgreSqlDatabases` resource, a `Radius.Security/secrets` resource, a `@secure()` password parameter, and two`connections`entries on the container. The highlighted lines are the additions:
14
14
15
15
<divclass="td-max-width-on-larger-screens"style="margin-bottom: -2rem;"><ahref="https://github.com/radius-project/samples/blob/{{< param version >}}/samples/demo/app-postgresql.bicep"target="_blank"rel="noopener">samples/demo/app-postgresql.bicep</a></div>
16
16
17
-
{{< rad file="/static/samples/demo/app-postgresql.bicep" embed=true markdownConfig=` {hl_lines=["6-8","36-40","44-54"]}` >}}
17
+
{{< rad file="/static/samples/demo/app-postgresql.bicep" embed=true markdownConfig=` {hl_lines=["6-8","36-43","47-57","59-70"]}` >}}
18
18
19
-
The `postgresql` resource is provisioned by the PostgreSQL recipe in the default Recipe Pack. The `password` parameter is declared with `@secure()`, which keeps its value out of deployment logs and history and lets you supply the password at deploy time instead of hardcoding it. Because the `password` propertyis `x-radius-sensitive` on the Resource Type, Radius also encrypts it and redacts it from reads.
19
+
The `postgresql` resource is provisioned by the PostgreSQL Recipe in the default Recipe Pack. The `password` parameter is declared with `@secure()`, which keeps its value out of deployment logs and history and lets you supply the password at deploy time instead of hardcoding it. The application passes that value directly to the database's `password` property. Because the property is `x-radius-sensitive`, Radius encrypts it and redacts it from reads.
20
20
21
-
The `connections` entry tells Radius that the container depends on the database. Radius provisions the database first, then injects its connection details into the container as environment variables named `CONNECTION_POSTGRESQL_<PROPERTY>`, such as `CONNECTION_POSTGRESQL_HOST` and `CONNECTION_POSTGRESQL_PORT`.
21
+
The application also stores the same value under the `password` key of the authored `postgresqlCredentials` Secret instead of relying on database Recipe `result.secrets` for a developer-owned credential. The Secret has the same application and environment as the other resources, so it shares their lifecycle. Its resource name is deliberately different from the `postgresql-${environmentName}-credentials` Kubernetes Secret owned by the PostgreSQL Recipe.
22
+
23
+
The `postgresql` connection tells Radius that the container depends on the database. Radius provisions the database first, then injects its ordinary connection values as `CONNECTION_POSTGRESQL_HOST`, `CONNECTION_POSTGRESQL_PORT`, `CONNECTION_POSTGRESQL_DATABASE`, and `CONNECTION_POSTGRESQL_USERNAME`.
24
+
25
+
The `postgresqlCredentials` connection points directly to the authored Secret. With a compatible Kubernetes Container Recipe, Radius projects its `password` key through a Kubernetes `secretKeyRef` as `CONNECTION_POSTGRESQLCREDENTIALS_PASSWORD`. The secret value remains in the Secret and is not copied into Recipe output or plaintext container configuration.
26
+
27
+
> **Caution:** The Radius Demo displays all `CONNECTION_*` environment variables it receives, including this password, to illustrate connection injection. Do not display secret values in a production application.
28
+
>
29
+
> **Compatibility:** Automatic Secret connection projection requires a compatible Radius runtime and Kubernetes Container Recipe. In older or mixed-version environments, keep an explicit container `env.valueFrom.secretKeyRef` binding instead of changing a working model. Azure Container Instances behavior is unchanged.
22
30
23
31
## Redeploy the application
24
32
25
-
Deploy the updated definition from its published URL. The `--parameters password=` flag sets the database password, and `$(openssl rand -hex 16)` generates a random value on each deploy. This works in Bash and Zsh; in PowerShell, generate the value separately and pass it in:
33
+
Deploy the updated definition from its published URL. The `--parameters` argument sets the database password, and `$(openssl rand -hex 16)` generates a random value on each deploy. This works in Bash and Zsh; in PowerShell, generate the value separately and pass it in:
Radius creates the database and updates the container with the connection. Forward a local port to the container and open the application again:
37
+
Radius creates the database and authored Secret, then updates the container with both connections. Forward a local port to the container and open the application again:
Open [http://localhost:3000](http://localhost:3000). The Radius Connections section now lists the `postgresql` connection.
43
+
Open [http://localhost:3000](http://localhost:3000). The Radius Connections section now lists the `postgresql`database connection and the `postgresqlCredentials` Secret connection.
Open [http://localhost:7007](http://localhost:7007) and select the `demo-default` application. The graph shows the `demo-default` container connected to the `postgresql-default` database.
48
-
49
-
{{< image src="dashboard.png" alt="The Radius Dashboard showing the container connected to the PostgreSQL database" width=800px >}}
50
-
<br/>
53
+
Open [http://localhost:7007](http://localhost:7007), select the `demo-default` application, and use the application graph to inspect the container's connections to the `postgresql-default` database and `postgresql-credentials-default` Secret.
51
54
52
55
To learn more about modeling dependencies between resources, see [How to model application dependencies using connections]({{< ref "/applications/connections" >}}).
53
56
54
57
## Clean up
55
58
56
-
Delete the Radius Demo application:
59
+
Delete the Radius Demo application. Because the database and authored Secret belong to this application, Radius deletes them with the container:
57
60
58
61
<!-- TODO: Remove the `--preview` flag when the Radius.Core Application implementation is no longer in preview. -->
59
62
```bash
@@ -68,6 +71,6 @@ rad uninstall kubernetes --purge
68
71
69
72
## Next steps
70
73
71
-
You have installed Radius, deployed the Radius Demo application, and connected it to a PostgreSQL database. Continue with the hands-on labs for deeper, real-world scenarios.
74
+
You have installed Radius, deployed the Radius Demo application, and connected it to a PostgreSQL database and an authored Secret. Continue with the hands-on labs for deeper, real-world scenarios.
72
75
73
76
{{< button text="Next step: Explore the labs" page="getting-started/labs" >}}
0 commit comments