# WithKubernetesPersistentVolume

- Module: [Aspire.Hosting.Kubernetes](/reference/api/go/aspire.hosting.kubernetes.md)
- Version: `17.0.0`
- Kind: `method`
- Defined on: `IComputeResource`
- Source: [GitHub](https://github.com/microsoft/aspire/tree/2d325b13709752ba6d9a943635c5e2940a2530c0)

Binds a workload to a Kubernetes persistent volume by matching volume name

## Remarks

To bind a workload that does not have a matching named mount (for
example a `ProjectResource`), use the overload that accepts a
`mountPath` instead. The generated pod uses an Aspire-managed
`fsGroup` of `2000` with an `OnRootMismatch` change policy so
non-root containers can access supported volumes without matching the image's
primary group. Use
`PublishAsKubernetesService`
to customize the pod security context when a different group or policy is required.

## Definition

```go
func (IComputeResource) WithKubernetesPersistentVolume(volume KubernetesPersistentVolumeResource) IComputeResource
```

## Parameters

- `volume` ([`KubernetesPersistentVolumeResource`](/reference/api/go/aspire.hosting.kubernetes/kubernetespersistentvolumeresource.md)) -- The persistent volume resource to bind to.

## Returns

`IComputeResource` -- The same builder for chaining.

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

## Applies to

- `CSharpAppResource`
- `ContainerResource`
- `DotnetToolResource`
- `ExecutableResource`
- [`KubernetesAspireDashboardResource`](/reference/api/go/aspire.hosting.kubernetes/kubernetesaspiredashboardresource.md)
- `ProjectResource`
