# K3sServiceEndpointResource

- Kind: `class`
- Package: [CommunityToolkit.Aspire.Hosting.K3s](/reference/api/csharp/communitytoolkit.aspire.hosting.k3s.md)
- Version: `13.4.1-beta.706`
- Namespace: `Aspire.Hosting.ApplicationModel`
- Target framework: `net10.0`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d479e13473b1d29d06b974f144a0049289a3cb5c/src/CommunityToolkit.Aspire.Hosting.K3s/K3sServiceEndpointResource.cs)
- Inherits: `Resource`
- Implements: `IExpressionValue`, `IManifestExpressionProvider`, `IResource`, `IResourceWithConnectionString`, `IResourceWithParent`, `IResourceWithParent<K3sClusterResource>`, `IResourceWithWaitSupport`, `IValueProvider`, `IValueWithReferences`

Represents a Kubernetes Service exposed from a k3s cluster as an Aspire endpoint resource.

## Definition

```csharp
namespace Aspire.Hosting.ApplicationModel;

public sealed class K3sServiceEndpointResource
    : Aspire.Hosting.ApplicationModel.Resource,
      Aspire.Hosting.ApplicationModel.IExpressionValue,
      Aspire.Hosting.ApplicationModel.IManifestExpressionProvider,
      Aspire.Hosting.ApplicationModel.IResource,
      Aspire.Hosting.ApplicationModel.IResourceWithConnectionString,
      Aspire.Hosting.ApplicationModel.IResourceWithParent,
      Aspire.Hosting.ApplicationModel.IResourceWithParent<Aspire.Hosting.ApplicationModel.K3sClusterResource>,
      Aspire.Hosting.ApplicationModel.IResourceWithWaitSupport,
      Aspire.Hosting.ApplicationModel.IValueProvider,
      Aspire.Hosting.ApplicationModel.IValueWithReferences
{
    // ...
}
```

## ATS metadata

### ATS export

- Type ID: `CommunityToolkit.Aspire.Hosting.K3s/K3sServiceEndpointResource`
- Public instance properties are exported as ATS capabilities.

## Remarks

An in-process WebSocket port-forward bridges the cluster service to a host port when the cluster is ready. Dependent resources receive the service URL via the standard Aspire service-discovery environment variable `services__{name}__url`:

- Host processes receive `http(s)://localhost:{port}`.
- Containers receive `http(s)://host.docker.internal:{port}`.

Use `WaitFor(endpoint)` on dependent resources to ensure the port-forward is active before they start.

## Constructors

- [K3sServiceEndpointResource(string, string, int, string, K3sClusterResource)](/reference/api/csharp/communitytoolkit.aspire.hosting.k3s/k3sserviceendpointresource/constructors.md#constructor-string-string-int-string-k3sclusterresource) -- Represents a Kubernetes Service exposed from a k3s cluster as an Aspire endpoint resource.

## Properties

- [ConnectionStringEnvironmentVariable](/reference/api/csharp/communitytoolkit.aspire.hosting.k3s/k3sserviceendpointresource/properties.md#connectionstringenvironmentvariable) : `string?` `get` -- The environment variable name used to inject the service URL into dependents ( `services__{name}__url`), following the Aspire service-discovery convention.
- [ConnectionStringExpression](/reference/api/csharp/communitytoolkit.aspire.hosting.k3s/k3sserviceendpointresource/properties.md#connectionstringexpression) : `ReferenceExpression` `get` -- Gets the manifest expression for the service URL. Resolves to `http(s)://localhost:{hostPort}` when the endpoint is ready.
- [HostPort](/reference/api/csharp/communitytoolkit.aspire.hosting.k3s/k3sserviceendpointresource/properties.md#hostport) : `int` `get` -- Gets the host port bound by the port-forward listener.
- [Namespace](/reference/api/csharp/communitytoolkit.aspire.hosting.k3s/k3sserviceendpointresource/properties.md#namespace) : `string` `get` -- Gets the Kubernetes namespace that contains the Service.
- [Parent](/reference/api/csharp/communitytoolkit.aspire.hosting.k3s/k3sserviceendpointresource/properties.md#parent) : [K3sClusterResource](/reference/api/csharp/communitytoolkit.aspire.hosting.k3s/k3sclusterresource.md) `get` -- Gets the parent resource of type [K3sClusterResource](/reference/api/csharp/communitytoolkit.aspire.hosting.k3s/k3sclusterresource.md).
- [ServiceName](/reference/api/csharp/communitytoolkit.aspire.hosting.k3s/k3sserviceendpointresource/properties.md#servicename) : `string` `get` -- Gets the name of the Kubernetes Service being forwarded.
- [ServicePort](/reference/api/csharp/communitytoolkit.aspire.hosting.k3s/k3sserviceendpointresource/properties.md#serviceport) : `int` `get` -- Gets the port number declared on the Kubernetes Service.

## Methods

- [GetConnectionStringAsync(CancellationToken)](/reference/api/csharp/communitytoolkit.aspire.hosting.k3s/k3sserviceendpointresource/methods.md#getconnectionstringasync-cancellationtoken) : `ValueTask<string?>` -- Returns the host-accessible service URL, or `null` if the port-forward is not yet active.
