How To: Configure a gateway for routing internet traffic

Learn how to expose a service to the internet via a gateway

This guide will walk you through how to setup a gateway for routing internet traffic to a service.

Prerequisites

Step 1: Define a container

Begin by defining the service you wish to expose to the internet in a new file named app.bicep. This example uses the Radius demo container:

extension radius

@description('The application ID being deployed. Injected automtically by the rad CLI')
param application string

resource frontend 'Applications.Core/containers@2023-10-01-preview' = {
  name: 'frontend'
  properties: {
    application: application
    container: {
      image: 'ghcr.io/radius-project/samples/demo:latest'
      ports: {
        web: {
          containerPort: 3000
        }
      }
    }
  }
}

Step 2: Add a gateway

Next, add a gateway to app.bicep, routing traffic to the root path ("/") to the frontend container. Note that when a hostname is not specified one is generated automatically.

resource gateway 'Applications.Core/gateways@2023-10-01-preview' = {
  name: 'gateway'
  properties: {
    application: application
    routes: [
      {
        path: '/'
        destination: 'http://${frontend.name}:3000'
      }
    ]
  }
}

Step 3: Deploy the app

Deploy the application with rad deploy:

rad deploy app.bicep -a gatewaydemo

The gateway endpoint will be printed at the end of the deployment:

Building app.bicep...
   Deploying template './app.bicep' for application 'gatewaydemo' and environment 'default' from workspace 'default'...

   Deployment In Progress...

   Completed            gateway         Applications.Core/gateways
   Completed            frontend        Applications.Core/containers

   Deployment Complete

   Resources:
      gateway         Applications.Core/gateways
      frontend        Applications.Core/containers

    Public endpoint http://1.1.1.1.nip.io/

Step 4: Interact with the application

Visit the endpoint to interact with the demo Radius container:

Done

Cleanup the application with ‘rad app delete’:

rad app delete gatewaydemo -y

Further reading