# WithLifetime

- 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 container lifetime for the k3s cluster and all its agent nodes.

## Remarks

Agent nodes are propagated immediately because DCP uses
`ContainerLifetimeAnnotation` to compute container identity. Deferring
propagation to `BeforeStartEvent` would be too late -- DCP determines whether
to reuse or recreate a persistent container before that event fires, so agents
would lose their persistent identity and be recreated as new containers each run.

## Definition

```go
func (K3sClusterResource) WithLifetime(lifetime ContainerLifetime) K3sClusterResource
```

## Parameters

- `lifetime` (`ContainerLifetime`) -- The container lifetime to apply.

## 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)
