Skip to content

Commit 22bb5de

Browse files
committed
[ACA] [323630] Add path-based routing how to and conceptual.
1 parent d8b5e44 commit 22bb5de

File tree

3 files changed

+193
-1
lines changed

3 files changed

+193
-1
lines changed

articles/container-apps/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,8 @@
354354
href: waf-app-gateway.md
355355
- name: Enable User Defined Routes (UDR)
356356
href: user-defined-routes.md
357+
- name: Use path-based routing
358+
href: how-to-use-path-based-rousing.md
357359
- name: Securing a custom VNET with an NSG
358360
href: firewall-integration.md
359361
- name: Use a private endpoint
Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
---
2+
title: Use path-based routing in Azure Container Apps (preview)
3+
description: Learn how to use path-based routing Azure Container Apps.
4+
services: container-apps
5+
author: craigshoemaker
6+
ms.service: azure-container-apps
7+
ms.custom: devx-track-azurecli, devx-track-bicep
8+
ms.topic: how-to
9+
ms.date: 02/20/2025
10+
ms.author: cshoe
11+
zone_pivot_groups: azure-cli-bicep
12+
---
13+
14+
# Use path-based routing with Azure Container Apps (preview)
15+
16+
In this article, you learn how to use path-based routing with Azure Container Apps.
17+
18+
## Prerequisites
19+
20+
- Azure account with an active subscription.
21+
- If you don't have one, you [can create one for free](https://azure.microsoft.com/free/).
22+
23+
- Install the [Azure CLI](/cli/azure/install-azure-cli).
24+
25+
::: zone pivot="bicep"
26+
27+
- [Bicep](/azure/azure-resource-manager/bicep/install)
28+
29+
::: zone-end
30+
31+
## Setup
32+
33+
To sign in to Azure from the CLI, run the following command and follow the prompts to complete the authentication process.
34+
35+
```azurecli
36+
az login
37+
```
38+
39+
To ensure you're running the latest version of the CLI, run the upgrade command.
40+
41+
```azurecli
42+
az upgrade
43+
```
44+
45+
Ignore any warnings about modules currently in use.
46+
47+
Next, install or update the Azure Container Apps extension for the CLI.
48+
49+
If you receive errors about missing parameters when you run `az containerapp` commands in Azure CLI or cmdlets from the `Az.App` module in PowerShell, be sure you have the latest version of the Azure Container Apps extension installed.
50+
51+
```azurecli
52+
az extension add --name containerapp --upgrade
53+
```
54+
55+
> [!NOTE]
56+
> Starting in May 2024, Azure CLI extensions no longer enable preview features by default. To access Container Apps [preview features](../articles/container-apps/whats-new.md), install the Container Apps extension with `--allow-preview true`.
57+
> ```azurecli
58+
> az extension add --name containerapp --upgrade --allow-preview true
59+
> ```
60+
61+
Now that the current extension or module is installed, register the `Microsoft.App` and `Microsoft.OperationalInsights` namespaces.
62+
63+
```azurecli
64+
az provider register --namespace Microsoft.App
65+
```
66+
67+
```azurecli
68+
az provider register --namespace Microsoft.OperationalInsights
69+
```
70+
71+
::: zone pivot="azure-cli"
72+
73+
## Create environment variables
74+
75+
Create the following environment variables.
76+
77+
```bash
78+
$CONTAINER_APP_1_NAME="my-container-app-1"
79+
$CONTAINER_APP_1_IMAGE="mcr.microsoft.com/k8se/quickstart:latest"
80+
$CONTAINER_APP_1_TARGET_PORT="80"
81+
$CONTAINER_APP_2_NAME="my-container-app-2"
82+
$CONTAINER_APP_2_IMAGE="mcr.microsoft.com/dotnet/samples:aspnetapp"
83+
$CONTAINER_APP_2_TARGET_PORT="8080"
84+
$LOCATION="eastus"
85+
$RESOURCE_GROUP="my-container-apps"
86+
$ENVIRONMENT_NAME="my-container-apps-env"
87+
$ROUTE_CONFIG_NAME="my-route-config"
88+
```
89+
90+
## Create container apps
91+
92+
Run the following command to create your first container app. This container app uses the Container Apps quickstart image.
93+
94+
```azurecli
95+
az containerapp up \
96+
--name $CONTAINER_APP_1_NAME \
97+
--resource-group $RESOURCE_GROUP \
98+
--location $LOCATION \
99+
--environment $ENVIRONMENT_NAME \
100+
--image $CONTAINER_APP_1_IMAGE \
101+
--target-port $CONTAINER_APP_1_TARGET_PORT \
102+
--ingress external \
103+
--query properties.configuration.ingress.fqdn
104+
```
105+
106+
Run the following command to create your second container app. This container app uses the ASP.NET quickstart image.
107+
108+
```azurecli
109+
az containerapp up \
110+
--name $CONTAINER_APP_2_NAME \
111+
--resource-group $RESOURCE_GROUP \
112+
--location $LOCATION \
113+
--environment $ENVIRONMENT_NAME \
114+
--image $CONTAINER_APP_2_IMAGE \
115+
--target-port $CONTAINER_APP_2_TARGET_PORT \
116+
--ingress external \
117+
--query properties.configuration.ingress.fqdn
118+
```
119+
120+
## Create HTTP route configuration
121+
122+
1. Create the following YAML file and save it as `routing.yml`.
123+
124+
```yaml
125+
rules:
126+
- description: App 1 rule
127+
routes:
128+
- match:
129+
prefix: /app1
130+
action:
131+
prefixRewrite: /
132+
targets:
133+
- containerApp: my-container-app-1
134+
- description: App 2 rule
135+
routes:
136+
- match:
137+
path: /app2
138+
action:
139+
prefixRewrite: /
140+
targets:
141+
- containerApp: my-container-app-2
142+
```
143+
144+
1. Run the following command to create the HTTP route configuration.
145+
146+
```azurecli
147+
az containerapp env http-route-config create \
148+
--http-route-config-name $ROUTE_CONFIG_NAME \
149+
--resource-group $RESOURCE_GROUP \
150+
--name $ENVIRONMENT_NAME \
151+
--yaml routing.yml \
152+
--query properties.fqdn
153+
```
154+
155+
Your HTTP route configuration fully qualified domain name (FQDN) looks like this example: `my-route-config.ambitiouspebble-11ba6155.eastus.azurecontainerapps.io`
156+
157+
::: zone-end
158+
159+
::: zone pivot="bicep"
160+
161+
::: zone-end
162+
163+
## Test HTTP route configuration
164+
165+
1. Browse to your HTTP route configuration FQDN with the path `/app1`. For example: `my-route-config.ambitiouspebble-11ba6155.eastus.azurecontainerapps.io/app1`. You see the Container Apps quickstart image.
166+
167+
1. Browse to your HTTP route configuration FQDN with the path `/app2`. For example: `my-route-config.ambitiouspebble-11ba6155.eastus.azurecontainerapps.io/app2`. You see the ASP.NET quickstart image.
168+
169+
## Clean up resources
170+
171+
If you're not going to continue to use this application, run the following command to delete the resource group along with all the resources created in this quickstart.
172+
173+
>[!CAUTION]
174+
> The following command deletes the specified resource group and all resources contained within it. If resources outside the scope of this quickstart exist in the specified resource group, they will also be deleted.
175+
176+
```azurecli
177+
az group delete --name my-container-apps
178+
```
179+
180+
> [!TIP]
181+
> Having issues? Let us know on GitHub by opening an issue in the [Azure Container Apps repo](https://github.com/microsoft/azure-container-apps).
182+
183+
## Related content
184+
185+
- [Quickstart and samples](https://github.com/Tratcher/HttpRouteConfigBicep/tree/master)
186+
- [Azure CLI reference](/cli/azure/containerapp/env/http-route-config?view=azure-cli-latest)

articles/container-apps/networking.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ms.service: azure-container-apps
77
ms.custom:
88
- ignite-2024
99
ms.topic: conceptual
10-
ms.date: 08/29/2023
10+
ms.date: 02/20/2025
1111
ms.author: cshoe
1212
---
1313

@@ -387,6 +387,10 @@ You can enable mTLS in the ARM template for Container Apps environments using th
387387

388388
---
389389

390+
### Path-based routing
391+
392+
393+
390394
## DNS
391395

392396
- **Custom DNS**: If your VNet uses a custom DNS server instead of the default Azure-provided DNS server, configure your DNS server to forward unresolved DNS queries to `168.63.129.16`. [Azure recursive resolvers](../virtual-network/virtual-networks-name-resolution-for-vms-and-role-instances.md#name-resolution-that-uses-your-own-dns-server) uses this IP address to resolve requests. When configuring your NSG or firewall, don't block the `168.63.129.16` address, otherwise, your Container Apps environment won't function correctly.

0 commit comments

Comments
 (0)