# K3sClusterResource.WithLifetime

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

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
type K3sClusterResource interface {
    // ... omitted for brevity
    WithLifetime(lifetime ContainerLifetime) K3sClusterResource
}
```

## Signature

```go
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()`.

## Defined on

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