diff --git a/src/frontend/src/content/docs/deployment/kubernetes-ingress.mdx b/src/frontend/src/content/docs/deployment/kubernetes-ingress.mdx index c5da816d5..0d9f468bc 100644 --- a/src/frontend/src/content/docs/deployment/kubernetes-ingress.mdx +++ b/src/frontend/src/content/docs/deployment/kubernetes-ingress.mdx @@ -22,6 +22,19 @@ Aspire provides first-class APIs for defining Ingress and Gateway API resources and is the recommended path for that scenario. + + ## Ingress vs. Gateway API Kubernetes offers two approaches for routing external traffic to your services: @@ -51,6 +64,51 @@ When you use `AddIngress()` or `AddGateway()`, Aspire generates additional Kuber - A `gateway.networking.k8s.io/v1 Gateway` resource with listeners (HTTP on port 80, HTTPS on port 443 if TLS is configured) - One or more `HTTPRoute` resources attached to the Gateway, grouped by hostname +## Routing paths to services + +Use `WithPath` on an Ingress (or `WithRoute` on a Gateway) to forward traffic for a URL path to one of your Aspire services. Each call adds a rule to the generated `Ingress` (or `HTTPRoute`) resource pointing at the named endpoint's backing Kubernetes service. + + + +```csharp title="AppHost.cs" +var api = builder.AddProject("api"); +var web = builder.AddProject("web"); + +var ingress = k8s.AddIngress("public") + .WithIngressClass("nginx") + .WithHostname("app.example.com") + .WithTls(); + +// Route /api/* to the API service and everything else to the web frontend. +ingress.WithPath("/api", api.GetEndpoint("http")); +ingress.WithPath("/", web.GetEndpoint("http")); +``` + + +```typescript title="apphost.mts" +const api = await builder.addProject('api'); +const web = await builder.addProject('web'); + +const ingress = await k8s.addIngress('public'); +await ingress.withIngressClass('nginx'); +await ingress.withHostname('app.example.com'); +await ingress.withTls(); + +// Route /api/* to the API service and everything else to the web frontend. +await ingress.withPath('/api', api.getEndpoint('http')); +await ingress.withPath('/', web.getEndpoint('http')); +``` + + + +`WithPath` defaults to a `Prefix` match — pass an `IngressPathType` argument to request `Exact` or `ImplementationSpecific` matching when your controller supports it. There's also a host-scoped overload (`WithPath("api.example.com", "/", endpoint)`) for routing different hostnames to different backends from the same Ingress. If you'd rather forward all unmatched traffic to a single service without enumerating paths, call `WithDefaultBackend(endpoint)` instead — the two APIs can be combined. + + + ## TLS and certificates When you configure TLS with `WithTls()`, Aspire handles the initial bootstrapping: diff --git a/src/frontend/src/content/docs/whats-new/aspire-13-3.mdx b/src/frontend/src/content/docs/whats-new/aspire-13-3.mdx index 74ceb4594..aac55e263 100644 --- a/src/frontend/src/content/docs/whats-new/aspire-13-3.mdx +++ b/src/frontend/src/content/docs/whats-new/aspire-13-3.mdx @@ -392,7 +392,7 @@ var ingress = k8s.AddIngress("public") .WithTls("api-cert"); // Route requests at "/" to the project's HTTP endpoint. -ingress.WithRoute("/", api.GetEndpoint("http")); +ingress.WithPath("/", api.GetEndpoint("http")); ``` diff --git a/src/frontend/src/content/docs/whats-new/aspire-13-4.mdx b/src/frontend/src/content/docs/whats-new/aspire-13-4.mdx index 7710d58bf..ba650ebe9 100644 --- a/src/frontend/src/content/docs/whats-new/aspire-13-4.mdx +++ b/src/frontend/src/content/docs/whats-new/aspire-13-4.mdx @@ -272,6 +272,10 @@ For AKS, `AddAzureKubernetesEnvironment` now wires Azure Application Gateway for Aspire 13.4 adds a Kubernetes manifest resource API for arbitrary manifests and an `AddHelmChart` API for installing external Helm charts as deployment pipeline steps. These APIs make it possible to include Kubernetes-native resources, ingress controllers, monitoring stacks, and other third-party charts alongside the resources generated from your Aspire application model. +### Ingress `WithRoute` renamed to `WithPath` + +The Kubernetes `Ingress` routing API has been renamed from `WithRoute(...)` to `WithPath(...)` to better reflect the Kubernetes Ingress path-rule terminology and to disambiguate it from the Gateway API. Update existing AppHosts that call `ingress.WithRoute(...)` to call `ingress.WithPath(...)` instead. The Gateway API equivalent (`gateway.WithRoute(...)`) is unchanged. + ### Consolidated Helm chart configuration Helm chart name, version, description, release name, and namespace are now configured through the `WithHelm(...)` extension method. This replaces the previous parallel property-based configuration surface on `KubernetesEnvironmentResource` with one fluent entry point.