# K3sServiceEndpointExtensions Methods

- Package: [CommunityToolkit.Aspire.Hosting.K3s](/reference/api/csharp/communitytoolkit.aspire.hosting.k3s.md)
- Type: [K3sServiceEndpointExtensions](/reference/api/csharp/communitytoolkit.aspire.hosting.k3s/k3sserviceendpointextensions.md)
- Kind: `Methods`
- Members: `1`

Extension methods for exposing Kubernetes services from a k3s cluster into the Aspire network.

<a id="addserviceendpoint"></a>
<a id="addserviceendpoint-iresourcebuilder-k3sclusterresource-string-string-int-string-string"></a>

## AddServiceEndpoint(IResourceBuilder<K3sClusterResource>, string, string, int, string, string?)

- Name: `AddServiceEndpoint(IResourceBuilder<K3sClusterResource>, string, string, int, string, string?)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<K3sServiceEndpointResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d479e13473b1d29d06b974f144a0049289a3cb5c/src/CommunityToolkit.Aspire.Hosting.K3s/K3sBuilderExtensions.ServiceEndpoint.cs#L79-L129)

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

```csharp
public static class K3sServiceEndpointExtensions
{
    public static IResourceBuilder<K3sServiceEndpointResource> AddServiceEndpoint(
        this IResourceBuilder<K3sClusterResource> builder,
        string name,
        string serviceName,
        int servicePort,
        string @namespace = "default",
        string? scheme = null)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<K3sClusterResource>`)
  The k3s cluster resource builder.
- `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` (`int`)
  The port number declared on the Kubernetes Service (the `port` field, not `targetPort`). Must be in the range 1 - 65535.
- `namespace` (`string`) `optional`
  The Kubernetes namespace that contains the Service. Defaults to `default`.
- `scheme` (`string?`) `optional`
  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

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

## Exceptions

- `ArgumentNullException` -- `builder`, `name`, or `serviceName` is `null`.
- `ArgumentException` -- `serviceName` or `namespace` is empty or whitespace.
- `ArgumentOutOfRangeException` -- `servicePort` is not in the range 1 - 65535.

## 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](/reference/api/csharp/communitytoolkit.aspire.hosting.k3s/helmreleaseresource.md) or [K8sManifestResource](/reference/api/csharp/communitytoolkit.aspire.hosting.k3s/k8smanifestresource.md) 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}`.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.
