# K3sClusterResource

- Module: [CommunityToolkit.Aspire.Hosting.K3s](/reference/api/typescript/communitytoolkit.aspire.hosting.k3s.md)
- Version: `13.5.0`
- Kind: `handle`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/tree/4ff8268fbd97ddd23cb73dc8eff9cc92718156d1)

Represents a k3s Kubernetes cluster running as a privileged container resource. Injects the cluster's kubeconfig into a dependent resource. - -

## Definition

```typescript
interface K3sClusterResource
  extends IComputeResource,
    IExpressionValue,
    IManifestExpressionProvider,
    IResource,
    IResourceWithArgs,
    IResourceWithConnectionString,
    IResourceWithEndpoints,
    IResourceWithEnvironment,
    IResourceWithProbes,
    IResourceWithWaitSupport,
    IValueProvider,
    IValueWithReferences {
  readonly apiEndpoint: EndpointReference;
  readonly connectionStringEnvironmentVariable: string;
  readonly connectionStringExpression: ReferenceExpression;
  addHelmRelease(
      name: string,
      chart: string,
      repo?: string,
      version?: string,
      namespace?: string): HelmReleaseResource;
  addK8sManifest(
      name: string,
      path: string): K8sManifestResource;
  addServiceEndpoint(
      name: string,
      serviceName: string,
      servicePort: number,
      namespace?: string,
      scheme?: string): K3sServiceEndpointResource;
  withAgentCount(count: number): K3sClusterResource;
  withDataVolume(name?: string): K3sClusterResource;
  withDisabledComponent(component: string): K3sClusterResource;
  withExtraArg(arg: string): K3sClusterResource;
  withHelmImage(
      tag?: string,
      image?: string,
      registry?: string): K3sClusterResource;
  withK3sVersion(tag: string): K3sClusterResource;
  withKubectlImage(
      tag?: string,
      image?: string,
      registry?: string): K3sClusterResource;
  withLifetime(lifetime: ContainerLifetime): K3sClusterResource;
  withPodSubnet(cidr: string): K3sClusterResource;
  withServiceSubnet(cidr: string): K3sClusterResource;
}
```

## Properties

- `apiEndpoint`: `EndpointReference` `get` -- Gets the endpoint reference for the k3s API server (port 6443).
- `connectionStringEnvironmentVariable`: `string` `get` -- Overrides the default `ConnectionStrings__` prefix so Aspire injects `KUBECONFIG`.
- `connectionStringExpression`: `ReferenceExpression` `get` -- Manifest expression for the local kubeconfig path.

## Methods

- [addHelmRelease](/reference/api/typescript/communitytoolkit.aspire.hosting.k3s/k3sclusterresource/addhelmrelease.md) -- `method` -- Installs a Helm chart into the k3s cluster.
    ```typescript
  addHelmRelease(name: string, chart: string, repo?: string, version?: string, namespace?: string): HelmReleaseResource
  ```
- [addK8sManifest](/reference/api/typescript/communitytoolkit.aspire.hosting.k3s/k3sclusterresource/addk8smanifest.md) -- `method` -- Applies Kubernetes YAML manifests or a Kustomize overlay to the cluster.
    ```typescript
  addK8sManifest(name: string, path: string): K8sManifestResource
  ```
- [addServiceEndpoint](/reference/api/typescript/communitytoolkit.aspire.hosting.k3s/k3sclusterresource/addserviceendpoint.md) -- `method` -- Exposes a Kubernetes Service from the cluster as an Aspire endpoint resource.
    ```typescript
  addServiceEndpoint(name: string, serviceName: string, servicePort: number, namespace?: string, scheme?: string): K3sServiceEndpointResource
  ```
- [withAgentCount](/reference/api/typescript/communitytoolkit.aspire.hosting.k3s/k3sclusterresource/withagentcount.md) -- `method` -- Sets the number of k3s agent (worker) nodes to add to the cluster.
    ```typescript
  withAgentCount(count: number): K3sClusterResource
  ```
- [withDataVolume](/reference/api/typescript/communitytoolkit.aspire.hosting.k3s/k3sclusterresource/withdatavolume.md) -- `method` -- Mounts a named Docker volume at the k3s data directory so cluster state persists across AppHost restarts.
    ```typescript
  withDataVolume(name?: string): K3sClusterResource
  ```
- [withDisabledComponent](/reference/api/typescript/communitytoolkit.aspire.hosting.k3s/k3sclusterresource/withdisabledcomponent.md) -- `method` -- Disables a built-in k3s component (`--disable=<component>`).
    ```typescript
  withDisabledComponent(component: string): K3sClusterResource
  ```
- [withExtraArg](/reference/api/typescript/communitytoolkit.aspire.hosting.k3s/k3sclusterresource/withextraarg.md) -- `method` -- Appends a raw argument to the `k3s server` command line.
    ```typescript
  withExtraArg(arg: string): K3sClusterResource
  ```
- [withHelmImage](/reference/api/typescript/communitytoolkit.aspire.hosting.k3s/k3sclusterresource/withhelmimage.md) -- `method` -- Overrides the container image used to run `helm upgrade --install` for all `HelmReleaseResource` children of this cluster.
    ```typescript
  withHelmImage(tag?: string, image?: string, registry?: string): K3sClusterResource
  ```
- [withK3sVersion](/reference/api/typescript/communitytoolkit.aspire.hosting.k3s/k3sclusterresource/withk3sversion.md) -- `method` -- Sets the k3s image version used by the cluster server and all its agent nodes.
    ```typescript
  withK3sVersion(tag: string): K3sClusterResource
  ```
- [withKubectlImage](/reference/api/typescript/communitytoolkit.aspire.hosting.k3s/k3sclusterresource/withkubectlimage.md) -- `method` -- Overrides the container image used to run `kubectl apply` for all `K8sManifestResource` children of this cluster.
    ```typescript
  withKubectlImage(tag?: string, image?: string, registry?: string): K3sClusterResource
  ```
- [withLifetime](/reference/api/typescript/communitytoolkit.aspire.hosting.k3s/k3sclusterresource/withlifetime.md) -- `method` -- Sets the container lifetime for the k3s cluster and all its agent nodes.
    ```typescript
  withLifetime(lifetime: ContainerLifetime): K3sClusterResource
  ```
- [withPodSubnet](/reference/api/typescript/communitytoolkit.aspire.hosting.k3s/k3sclusterresource/withpodsubnet.md) -- `method` -- Sets the CIDR range for pod IP addresses (`--cluster-cidr`).
    ```typescript
  withPodSubnet(cidr: string): K3sClusterResource
  ```
- [withServiceSubnet](/reference/api/typescript/communitytoolkit.aspire.hosting.k3s/k3sclusterresource/withservicesubnet.md) -- `method` -- Sets the CIDR range for Service cluster IPs (`--service-cidr`).
    ```typescript
  withServiceSubnet(cidr: string): K3sClusterResource
  ```
