Skip to content
Docs Try Aspire
Docs Try

KubernetesGatewayResource

Class net8.0
📦 Aspire.Hosting.Kubernetes v13.3.0-preview.1.26254.5
Represents a Kubernetes Gateway API Gateway as a first-class resource in the Aspire application model. A Gateway defines listeners (ports, protocols, TLS) and HTTPRoutes attach to it for routing.
namespace Aspire.Hosting.Kubernetes;
public class KubernetesGatewayResource
: Aspire.Hosting.ApplicationModel.Resource,
Aspire.Hosting.ApplicationModel.IResource,
Aspire.Hosting.ApplicationModel.IResourceWithParent,
Aspire.Hosting.ApplicationModel.IResourceWithParent<Aspire.Hosting.Kubernetes.KubernetesEnvironmentResource>
{
// ...
}
ResourceIResourceIResourceWithParentIResourceWithParent<KubernetesEnvironmentResource>

Create a gateway using KubernetesGatewayExtensions.AddGateway and configure routes using KubernetesGatewayExtensions.WithRoute.

At publish time, the gateway generates a gateway.networking.k8s.io/v1 Gateway resource with auto-inferred listeners and one or more HTTPRoute resources in the Helm chart output.

var k8s = builder.AddKubernetesEnvironment("k8s");
var gateway = k8s.AddGateway("public")
.WithGatewayClass("azure-alb-external");
var api = builder.AddProject<MyApi>("api");
gateway.WithRoute("/api", api.GetEndpoint("http"));