# KindClusterResourceBuilderExtensions Methods

- Package: [CommunityToolkit.Aspire.Hosting.Kind](/reference/api/csharp/communitytoolkit.aspire.hosting.kind.md)
- Type: [KindClusterResourceBuilderExtensions](/reference/api/csharp/communitytoolkit.aspire.hosting.kind/kindclusterresourcebuilderextensions.md)
- Kind: `Methods`
- Members: `6`

Extension methods for adding Kind cluster resources to the distributed application builder.

<a id="addkindcluster"></a>
<a id="addkindcluster-idistributedapplicationbuilder-string"></a>

## AddKindCluster(IDistributedApplicationBuilder, string)

- Name: `AddKindCluster(IDistributedApplicationBuilder, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<KindClusterResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d479e13473b1d29d06b974f144a0049289a3cb5c/src/CommunityToolkit.Aspire.Hosting.Kind/KindClusterResourceBuilderExtensions.cs#L32-L116)

Adds a Kind cluster resource to the application model.

```csharp
public static class KindClusterResourceBuilderExtensions
{
    public static IResourceBuilder<KindClusterResource> AddKindCluster(
        this IDistributedApplicationBuilder builder,
        string name)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IDistributedApplicationBuilder`)
  The `Hosting.IDistributedApplicationBuilder`.
- `name` (`string`)
  The name of the Kind cluster.

## Returns

`IResourceBuilder<KindClusterResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

<a id="withclusterlifetime"></a>
<a id="withclusterlifetime-iresourcebuilder-t-clusterlifetime"></a>

## WithClusterLifetime(IResourceBuilder<T>, ClusterLifetime)

- Name: `WithClusterLifetime(IResourceBuilder<T>, ClusterLifetime)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<T>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d479e13473b1d29d06b974f144a0049289a3cb5c/src/CommunityToolkit.Aspire.Hosting.Kind/KindClusterResourceBuilderExtensions.cs#L174-L176)

Sets the cluster lifetime. When [ClusterLifetime.Session](/reference/api/csharp/communitytoolkit.aspire.hosting.kind/clusterlifetime/fields.md) (the default), the cluster is deleted when the AppHost shuts down. When [ClusterLifetime.Persistent](/reference/api/csharp/communitytoolkit.aspire.hosting.kind/clusterlifetime/fields.md), the cluster survives AppHost restarts and is reused on next startup.

```csharp
public static class KindClusterResourceBuilderExtensions
{
    public static IResourceBuilder<T> WithClusterLifetime<T>(
        this IResourceBuilder<T> builder,
        ClusterLifetime lifetime)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<T>`)
  The resource builder.
- `lifetime` ([ClusterLifetime](/reference/api/csharp/communitytoolkit.aspire.hosting.kind/clusterlifetime.md))
  The desired cluster lifetime.

## Returns

`IResourceBuilder<T>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

<a id="withkindconfig"></a>
<a id="withkindconfig-iresourcebuilder-kindclusterresource-action-kindconfigmodel"></a>

## WithKindConfig(IResourceBuilder<KindClusterResource>, Action<KindConfigModel>)

- Name: `WithKindConfig(IResourceBuilder<KindClusterResource>, Action<KindConfigModel>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<KindClusterResource>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d479e13473b1d29d06b974f144a0049289a3cb5c/src/CommunityToolkit.Aspire.Hosting.Kind/KindClusterResourceBuilderExtensions.cs#L194-L199)

Customizes the Kind cluster configuration. The callback receives the [KindConfigModel](/reference/api/csharp/communitytoolkit.aspire.hosting.kind/kindconfigmodel.md) after default nodes have been populated, allowing arbitrary modifications before serialization to YAML.

```csharp
public static class KindClusterResourceBuilderExtensions
{
    public static IResourceBuilder<KindClusterResource> WithKindConfig(
        this IResourceBuilder<KindClusterResource> builder,
        Action<KindConfigModel> configure)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<KindClusterResource>`)
  The resource builder.
- `configure` (`Action<KindConfigModel>`)
  A callback to customize the Kind configuration model.

## Returns

`IResourceBuilder<KindClusterResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## Remarks

Multiple calls to this method compose: each callback is applied in order during config generation.

## ATS metadata

### Ignored by ATS

- Reason: Action<KindConfigModel> is not ATS-compatible. Configure Kind config through ATS-supported APIs.

<a id="withkubernetesversion"></a>
<a id="withkubernetesversion-iresourcebuilder-t-string"></a>

## WithKubernetesVersion(IResourceBuilder<T>, string)

- Name: `WithKubernetesVersion(IResourceBuilder<T>, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<T>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d479e13473b1d29d06b974f144a0049289a3cb5c/src/CommunityToolkit.Aspire.Hosting.Kind/KindClusterResourceBuilderExtensions.cs#L132-L137)

Sets the Kubernetes version for the Kind cluster.

```csharp
public static class KindClusterResourceBuilderExtensions
{
    public static IResourceBuilder<T> WithKubernetesVersion<T>(
        this IResourceBuilder<T> builder,
        string version)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<T>`)
  The resource builder.
- `version` (`string`)
  The Kubernetes version (e.g., "v1.32.2").

## Returns

`IResourceBuilder<T>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

<a id="withreference"></a>
<a id="withreference-iresourcebuilder-t-iresourcebuilder-kindclusterresource"></a>

## WithReference(IResourceBuilder<T>, IResourceBuilder<KindClusterResource>)

- Name: `WithReference(IResourceBuilder<T>, IResourceBuilder<KindClusterResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<T>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d479e13473b1d29d06b974f144a0049289a3cb5c/src/CommunityToolkit.Aspire.Hosting.Kind/KindClusterResourceBuilderExtensions.cs#L262-L269)

Configures a non-container resource to reference the Kind cluster by injecting kubeconfig environment variables.

```csharp
public static class KindClusterResourceBuilderExtensions
{
    public static IResourceBuilder<T> WithReference<T>(
        this IResourceBuilder<T> builder,
        IResourceBuilder<KindClusterResource> kind)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<T>`)
  The resource builder.
- `kind` (`IResourceBuilder<KindClusterResource>`)
  The Kind cluster resource builder.

## Returns

`IResourceBuilder<T>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## Remarks

This overload sets `KUBECONFIG` to the host kubeconfig path, which is appropriate for resources that execute on the host (e.g., executables, projects).

For container resources, use the [KindContainerExtensions.WithReference(IResourceBuilder<ContainerResource>, IResourceBuilder<KindClusterResource>)](/reference/api/csharp/communitytoolkit.aspire.hosting.kind/kindcontainerextensions/methods.md#withreference-iresourcebuilder-containerresource-iresourcebuilder-kindclusterresource) overload instead, which handles container-specific requirements like bind-mounting and network connectivity.

## ATS metadata

### ATS export

- Capability ID: `CommunityToolkit.Aspire.Hosting.Kind/withKindClusterReference`

<a id="withworkernodes"></a>
<a id="withworkernodes-iresourcebuilder-t-int"></a>

## WithWorkerNodes(IResourceBuilder<T>, int)

- Name: `WithWorkerNodes(IResourceBuilder<T>, int)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<T>`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/d479e13473b1d29d06b974f144a0049289a3cb5c/src/CommunityToolkit.Aspire.Hosting.Kind/KindClusterResourceBuilderExtensions.cs#L153-L156)

Sets the number of worker nodes for the Kind cluster.

```csharp
public static class KindClusterResourceBuilderExtensions
{
    public static IResourceBuilder<T> WithWorkerNodes<T>(
        this IResourceBuilder<T> builder,
        int count)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<T>`)
  The resource builder.
- `count` (`int`)
  The number of worker nodes. Must be zero or greater.

## Returns

`IResourceBuilder<T>` -- A reference to the `ApplicationModel.IResourceBuilder`1`.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.
