# K3sClusterResource.AddServiceEndpoint

- Module: [CommunityToolkit.Aspire.Hosting.K3s](/reference/api/go/communitytoolkit.aspire.hosting.k3s.md)
- Defined on: [K3sClusterResource](/reference/api/go/communitytoolkit.aspire.hosting.k3s/k3sclusterresource.md)
- Version: `13.6.1`
- Kind: `method`

Exposes a Kubernetes Service from the cluster as an Aspire endpoint resource.

## Remarks

An in-process WebSocket port-forward is started when the cluster becomes ready,
binding to `0.0.0.0:{allocatedHostPort}` so both host processes and DCP-network
containers can reach the service.
The endpoint transitions to `Running` only after the target Kubernetes Service
has at least one ready pod. Sequence chart installs or manifest applies before this
resource using `WaitForCompletion` on `HelmReleaseResource` or
`K8sManifestResource` to prevent the port-forward from polling indefinitely.
Use `WithReference(endpoint)` on a dependent resource builder to inject the
service URL as `services__{name}__url`. Host processes receive
`http(s)://localhost:{port}`; containers receive
`http(s)://host.docker.internal:{port}`.

## Definition

```go
type K3sClusterResource interface {
    // ... omitted for brevity
    AddServiceEndpoint(
        name string,
        serviceName string,
        servicePort float64,
        options ...*AddServiceEndpointOptions,
    ) K3sServiceEndpointResource
}
```

## Signature

```go
AddServiceEndpoint(
    name string,
    serviceName string,
    servicePort float64,
    options ...*AddServiceEndpointOptions,
) K3sServiceEndpointResource
```

## Parameters

- `name` (`string`) -- The Aspire resource name for this endpoint.
- `serviceName` (`string`) -- The name of the Kubernetes Service to forward, as it appears in `kubectl get svc`.
- `servicePort` (`float64`) -- The port number declared on the Kubernetes Service (the `port` field, not `targetPort`). Must be in the range 1 - 65535.
- `options` (`...*AddServiceEndpointOptions`) -- optional settings, see [Options](#options)

## Options

Optional parameters are passed in a trailing `options ...*AddServiceEndpointOptions` argument.

- `Namespace` (`*string`) -- The Kubernetes namespace that contains the Service. Defaults to `default`.
- `Scheme` (`*string`) -- The URL scheme (`http` or `https`) for the injected environment variable. When `null` (the default), the scheme is inferred from the port: ports 443 and 8443 use `https`, all others use `http`.

## Returns

[`K3sServiceEndpointResource`](/reference/api/go/communitytoolkit.aspire.hosting.k3s/k3sserviceendpointresource.md) -- A builder for the `K3sServiceEndpointResource`.

Returns a handle; failures surface later via `Err()`.

## Defined on

- [K3sClusterResource](/reference/api/go/communitytoolkit.aspire.hosting.k3s/k3sclusterresource.md) -- `handle`
