# KubernetesGatewayResource

- Module: [Aspire.Hosting.Kubernetes](/reference/api/typescript/aspire.hosting.kubernetes.md)
- Version: `13.4.0-preview.1.26281.18`
- Kind: `handle`
- Source: [GitHub](https://github.com/microsoft/aspire)

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.

## Definition

```typescript
interface KubernetesGatewayResource
  extends IResource,
    IResourceWithParent,
    KubernetesEnvironmentResource]] {
  withGatewayAnnotation(
      key: string,
      value: string): KubernetesGatewayResource;
  withGatewayAnnotationParam(
      key: string,
      value: ParameterResource): KubernetesGatewayResource;
  withGatewayClass(className: string): KubernetesGatewayResource;
  withGatewayClassParam(className: ParameterResource): KubernetesGatewayResource;
  withGatewayHostnameParam(hostname: ParameterResource): KubernetesGatewayResource;
  withGatewayHostRoute(
      host: string,
      path: string,
      endpoint: EndpointReference,
      pathType?: GatewayPathMatchType): KubernetesGatewayResource;
  withGatewayPathRoute(
      path: string,
      endpoint: EndpointReference,
      pathType?: GatewayPathMatchType): KubernetesGatewayResource;
  withGatewayTlsAuto(): KubernetesGatewayResource;
  withGatewayTlsIssuer(issuer: CertManagerIssuerResource): KubernetesGatewayResource;
  withGatewayTlsParam(secretName: ParameterResource): KubernetesGatewayResource;
  withHostname(hostname: string): KubernetesGatewayResource;
  withTls(secretName: string): KubernetesGatewayResource;
}
```

## Methods

- [withGatewayAnnotation](/reference/api/typescript/aspire.hosting.kubernetes/kubernetesgatewayresource/withgatewayannotation.md) -- `method` -- Adds a Kubernetes metadata annotation to the generated Gateway resource.
    ```typescript
  withGatewayAnnotation(key: string, value: string): KubernetesGatewayResource
  ```
- [withGatewayAnnotationParam](/reference/api/typescript/aspire.hosting.kubernetes/kubernetesgatewayresource/withgatewayannotationparam.md) -- `method` -- Adds a Kubernetes metadata annotation with a parameter value that will be resolved at deploy time.
    ```typescript
  withGatewayAnnotationParam(key: string, value: ParameterResource): KubernetesGatewayResource
  ```
- [withGatewayClass](/reference/api/typescript/aspire.hosting.kubernetes/kubernetesgatewayresource/withgatewayclass.md) -- `method` -- Sets the GatewayClass name that selects which controller implementation handles this gateway.
    ```typescript
  withGatewayClass(className: string): KubernetesGatewayResource
  ```
- [withGatewayClassParam](/reference/api/typescript/aspire.hosting.kubernetes/kubernetesgatewayresource/withgatewayclassparam.md) -- `method` -- Sets the GatewayClass name using a parameter that will be resolved at deploy time.
    ```typescript
  withGatewayClassParam(className: ParameterResource): KubernetesGatewayResource
  ```
- [withGatewayHostnameParam](/reference/api/typescript/aspire.hosting.kubernetes/kubernetesgatewayresource/withgatewayhostnameparam.md) -- `method` -- Adds a hostname using a parameter that will be resolved at deploy time.
    ```typescript
  withGatewayHostnameParam(hostname: ParameterResource): KubernetesGatewayResource
  ```
- [withGatewayHostRoute](/reference/api/typescript/aspire.hosting.kubernetes/kubernetesgatewayresource/withgatewayhostroute.md) -- `method` -- Adds a host-and-path-based routing rule to the gateway. The rule matches traffic for the specified host and path, routing it to the given endpoint's backing Kubernetes service. This generates an `HTTPRoute` resource with a `hostnames` filter.
    ```typescript
  withGatewayHostRoute(host: string, path: string, endpoint: EndpointReference, pathType?: GatewayPathMatchType): KubernetesGatewayResource
  ```
- [withGatewayPathRoute](/reference/api/typescript/aspire.hosting.kubernetes/kubernetesgatewayresource/withgatewaypathroute.md) -- `method` -- Adds a path-based routing rule to the gateway. The rule matches all hosts and routes traffic matching the specified path to the given endpoint's backing Kubernetes service. This generates an `HTTPRoute` resource attached to the Gateway.
    ```typescript
  withGatewayPathRoute(path: string, endpoint: EndpointReference, pathType?: GatewayPathMatchType): KubernetesGatewayResource
  ```
- [withGatewayTlsAuto](/reference/api/typescript/aspire.hosting.kubernetes/kubernetesgatewayresource/withgatewaytlsauto.md) -- `method` -- Configures TLS termination with an auto-generated secret name derived from the gateway name.
    ```typescript
  withGatewayTlsAuto(): KubernetesGatewayResource
  ```
- [withGatewayTlsIssuer](/reference/api/typescript/aspire.hosting.kubernetes/kubernetesgatewayresource/withgatewaytlsissuer.md) -- `method` -- Adds an HTTPS listener to the gateway and wires it to the supplied cert-manager `ClusterIssuer`. This adds the `cert-manager.io/cluster-issuer` annotation to the generated Gateway resource, causing cert-manager to provision and renew a certificate for each gateway listener hostname.
    ```typescript
  withGatewayTlsIssuer(issuer: CertManagerIssuerResource): KubernetesGatewayResource
  ```
- [withGatewayTlsParam](/reference/api/typescript/aspire.hosting.kubernetes/kubernetesgatewayresource/withgatewaytlsparam.md) -- `method` -- Configures TLS termination using a parameter for the secret name.
    ```typescript
  withGatewayTlsParam(secretName: ParameterResource): KubernetesGatewayResource
  ```
- [withHostname](/reference/api/typescript/aspire.hosting.kubernetes/kubernetesgatewayresource/withhostname.md) -- `method` -- Adds a hostname that this gateway's routes match. Multiple hostnames can be added by calling this method repeatedly. Hostnames are used as `hostnames` in generated `HTTPRoute` resources and as HTTPS listener hostnames when TLS is configured.
    ```typescript
  withHostname(hostname: string): KubernetesGatewayResource
  ```
- [withTls](/reference/api/typescript/aspire.hosting.kubernetes/kubernetesgatewayresource/withtls.md) -- `method` -- Configures TLS on a Kubernetes Gateway listener
    ```typescript
  withTls(secretName: string): KubernetesGatewayResource
  ```
