# WithAgentCount

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

Sets the number of k3s agent (worker) nodes to add to the cluster.

## Remarks

Agent nodes connect to the server via DCP DNS (`https://{name}:6443`) and use
k3s's built-in retry loop, so no explicit `WaitFor` is needed. The cluster health
check waits for `1 + count` nodes to reach `Ready` state before reporting
healthy. Use `WithLifetime` with `Persistent`
to keep agents alive across AppHost restarts and avoid node password hash mismatches.

## Definition

```go
func (K3sClusterResource) WithAgentCount(count float64) K3sClusterResource
```

## Parameters

- `count` (`float64`) -- The number of agent nodes. Zero or greater. Defaults to `0` (single-node cluster -- the server node acts as both control-plane and worker).

## Returns

[`K3sClusterResource`](/reference/api/go/communitytoolkit.aspire.hosting.k3s/k3sclusterresource.md) -- The same builder, for chaining.

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

## Applies to

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