Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove HTTP Routes #814

Merged
merged 8 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,74 @@
---
type: docs
title: "How To: Service to service networking"
linkTitle: "Service networking"
description: "Learn how your Radius services can communicate with each other"
weight: 200
slug: 'service-networking'
categories: "How-To"
---

This guide will show you how to have two services communicate with each other. In this example, we will have a frontend container that needs to communicate with a backend container.
AaronCrawfis marked this conversation as resolved.
Show resolved Hide resolved

<img src="overview.png" alt="Diagram of the frontend talking to the backend over HTTP port 80" width="400px" >

## Prerequisites

- [rad CLI]({{< ref "/guides/tooling/rad-cli/overview" >}})
- [Radius environment]({{< ref getting-started >}})

## Step 1: Define the services

First, we need to define the containers in a file named `app.bicep`. We will define two services: `frontend` and `backend`:
AaronCrawfis marked this conversation as resolved.
Show resolved Hide resolved

{{< rad file="snippets/1-app.bicep" embed=true markdownConfig="{linenos=table}" >}}

Note that the frontend container doesn't yet have a connection to the backend container. We will add that in the next step.
AaronCrawfis marked this conversation as resolved.
Show resolved Hide resolved

## Step 2: Add a connection

Now that we have defined the services, we can add the connection between them. Add a connection to `frontend`:
AaronCrawfis marked this conversation as resolved.
Show resolved Hide resolved

{{< rad file="snippets/2-app.bicep" embed=true marker="//FRONTEND" markdownConfig="{linenos=table,hl_lines=[\"14-18\"],linenostart=5}" >}}

## Step 3: Deploy the application

Deploy the application using the `rad deploy` command:

```bash
rad run app.bicep -a networking-demo
```

You should see the application deploy successfully and the log stream start:

```
Building app.bicep...
Deploying template 'app.bicep' for application 'networking-demo' and environment 'default' from workspace 'default'...

Deployment In Progress...

Completed backend Applications.Core/containers
Completed frontend Applications.Core/containers

Deployment Complete

Resources:
backend Applications.Core/containers
frontend Applications.Core/containers

Starting log stream...
```

## Step 4: Test the connection

Visit [http://localhost:3000](http://localhost:3000) in your browser. You should see a connection to the backend container, along with the environment variables that have automatically been set on the frontend container:

<img src="backend-connection.png" alt="Screenshot of the demo container showing the backend connections" width="600px" >

## Done

You have successfully added a connection between two containers. Make sure to delete your application to clean up the containers:

```bash
rad app delete networking-demo -y
```
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,34 @@
import radius as rad

@description('The application ID of the Radius environment. Automatically set by the rad CLI.')
param application string

resource frontend 'Applications.Core/containers@2023-10-01-preview' = {
name: 'frontend'
properties: {
application: application
container: {
image: 'radius.azurecr.io/tutorial/webapp:edge'
ports: {
web: {
containerPort: 3000
}
}
}
}
}

resource backend 'Applications.Core/containers@2023-10-01-preview' = {
name: 'backend'
properties: {
application: application
container: {
image: 'nginx:latest'
ports: {
web: {
containerPort: 80
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import radius as rad

@description('The application ID of the Radius environment. Automatically set by the rad CLI.')
param application string

//FRONTEND
resource frontend 'Applications.Core/containers@2023-10-01-preview' = {
name: 'frontend'
properties: {
application: application
container: {
image: 'radius.azurecr.io/tutorial/webapp:edge'
ports: {
web: {
containerPort: 3000
}
}
}
connections: {
backend: {
source: 'http://backend:80'
}
}
}
}
//FRONTEND

resource backend 'Applications.Core/containers@2023-10-01-preview' = {
name: 'backend'
properties: {
application: application
container: {
image: 'nginx:latest'
ports: {
web: {
containerPort: 80
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ resource demoGateway 'Applications.Core/gateways@2023-10-01-preview' = {
routes: [
{
path: '/'
destination: demoRoute.id
destination: 'http://${demoContainer.name}:3000'
}
]
tls: {
Expand All @@ -47,13 +47,6 @@ resource demoGateway 'Applications.Core/gateways@2023-10-01-preview' = {
}
}

resource demoRoute 'Applications.Core/httpRoutes@2023-10-01-preview' = {
name: 'demo-route'
properties: {
application: demoApplication.id
}
}

resource demoContainer 'Applications.Core/containers@2023-10-01-preview' = {
name: 'demo-container'
properties: {
Expand All @@ -63,7 +56,6 @@ resource demoContainer 'Applications.Core/containers@2023-10-01-preview' = {
ports: {
web: {
containerPort: 3000
provides: demoRoute.id
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ resource httpsGateway 'Applications.Core/gateways@2023-10-01-preview' = {
routes: [
{
path: '/'
destination: httpsRoute.id
destination: 'http://${httpsContainer.name}:3000'
}
]
tls: {
Expand All @@ -56,13 +56,6 @@ resource httpsGateway 'Applications.Core/gateways@2023-10-01-preview' = {
}
}

resource httpsRoute 'Applications.Core/httpRoutes@2023-10-01-preview' = {
name: 'https-route'
properties: {
application: httpsApplication.id
}
}

resource httpsContainer 'Applications.Core/containers@2023-10-01-preview' = {
name: 'https-container'
properties: {
Expand All @@ -72,7 +65,6 @@ resource httpsContainer 'Applications.Core/containers@2023-10-01-preview' = {
ports: {
web: {
containerPort: 3000
provides: httpsRoute.id
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ resource httpsGateway 'Applications.Core/gateways@2023-10-01-preview' = {
routes: [
{
path: '/'
destination: httpsRoute.id
destination: 'http://${httpsContainer.name}:3000'
}
]
tls: {
Expand All @@ -45,13 +45,6 @@ resource httpsGateway 'Applications.Core/gateways@2023-10-01-preview' = {
}
}

resource httpsRoute 'Applications.Core/httpRoutes@2023-10-01-preview' = {
name: 'https-route'
properties: {
application: httpsApplication.id
}
}

resource httpsContainer 'Applications.Core/containers@2023-10-01-preview' = {
name: 'https-container'
properties: {
Expand All @@ -61,7 +54,6 @@ resource httpsContainer 'Applications.Core/containers@2023-10-01-preview' = {
ports: {
web: {
containerPort: 3000
provides: httpsRoute.id
}
}
}
Expand Down
27 changes: 16 additions & 11 deletions docs/content/guides/author-apps/networking/overview/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,36 @@ linkTitle: "Overview"
description: "Learn how to add networking to your Radius application"
weight: 100
categories: "Overview"
tags: ["routes","gateways"]
---

Radius networking resources allow you to model:

- Communication between a user and a service
- Communication between services
- Communication between a user and a service

## HTTP Routes
<img src="networking.png" alt="Diagram of a gateway with traffic going to a frontend container, which in turn sends traffic to the basket and catalog containers" width="400px">

An `HttpRoute` resources defines HTTP communication between two [services]({{< ref "guides/author-apps/containers" >}}). They can be used to define both one-way communication, as well as cycles of communication between services.
## Service to service communication

<img src="networking-cycles.png" style="width:400px" alt="Diagram of Radius service-to-service networking with cycles" /><br />
Radius containers can define connections to other containers, just like they can define connections to dependencies.

Refer to the [HTTP Route schema]({{< ref httproute >}}) for more information on how to model HTTP routes.
Network connections are defined as strings containing:

A gateway can optionally be added for external users to access the Route.
- The **scheme** (protocol) of the connection _(http, https, tcp, etc.)_
- The **target** container/service to connect to _(basket, catalog, etc.)_
- The **port** to connect to _(80, 443, etc.)_

## Gateways
For example, a frontend container may need to connect to a basket container. The frontend container would define a connection to the basket container, with the scheme `http`, the target `basket`, and the port `3000`. The connection would look like this: `http://basket:3000`.

`Gateway` defines how requests are routed to different resources, and also provides the ability to expose traffic to the internet. Conceptually, gateways allow you to have a single point of entry for traffic in your application, whether it be internal or external traffic.
<img src="network-connection.png" alt="Diagram showing the components of a network connection" width="400px">

`Gateway` in Radius are split into two main pieces; the `Gateway` resource itself, which defines which port and protocol to listen on, and Route(s) which define the rules for routing traffic to different resources.
For more information on how to do service to service networking, visit the [service networking how-to guide]({{< ref howto-service-networking >}}):

{{< button text="How-To: Service to service networking" page="howto-service-networking" >}}

## Gateways

<img src="networking-gateways.png" style="width:400px" alt="Diagram of Radius gateways" /><br />
A `gateway` defines how requests are routed to different resources, and also provides the ability to expose traffic to the internet. Conceptually, gateways allow you to have a single point of entry for traffic in your application, whether it be internal or external.

Refer to the [Gateway schema]({{< ref gateway >}}) for more information on how to model gateways.

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

This file was deleted.

This file was deleted.

Loading
Loading