# KubernetesPersistentVolumeResource

- Kind: `class`
- Package: [Aspire.Hosting.Kubernetes](/reference/api/csharp/aspire.hosting.kubernetes.md)
- Version: `13.5.1-preview.1.26420.4`
- Namespace: `Aspire.Hosting.Kubernetes`
- Target framework: `net10.0`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/69db530a4816698cf1d5fa4557933e0ac4f127c6/src/Aspire.Hosting.Kubernetes/KubernetesPersistentVolumeResource.cs)
- Inherits: `Resource`
- Implements: `IResource`, `IResourceWithParent`, `IResourceWithParent<KubernetesEnvironmentResource>`

Represents a Kubernetes PersistentVolumeClaim as a first-class resource in the Aspire application model. A persistent volume resource carries the storage class, capacity, access modes, and metadata annotations needed to render a `v1.PersistentVolumeClaim` at publish time. Workloads bind to it with [KubernetesPersistentVolumeExtensions.WithPersistentVolume(IResourceBuilder<T>, IResourceBuilder<KubernetesPersistentVolumeResource>)](/reference/api/csharp/aspire.hosting.kubernetes/kubernetespersistentvolumeextensions/methods.md#withpersistentvolume-iresourcebuilder-t-iresourcebuilder-kubernetespersistentvolumeresource).

## Definition

```csharp
namespace Aspire.Hosting.Kubernetes;

public sealed class KubernetesPersistentVolumeResource
    : Aspire.Hosting.ApplicationModel.Resource,
      Aspire.Hosting.ApplicationModel.IResource,
      Aspire.Hosting.ApplicationModel.IResourceWithParent,
      Aspire.Hosting.ApplicationModel.IResourceWithParent<Aspire.Hosting.Kubernetes.KubernetesEnvironmentResource>
{
    // ...
}
```

## ATS metadata

### ATS export

- Type ID: `Aspire.Hosting.Kubernetes/KubernetesPersistentVolumeResource`

## Remarks

Bind a workload to the volume by either:

- Adding a matching `WithVolume("name", "/mount/path")` on a container resource and then calling `WithPersistentVolume(volume)`. The publisher matches by volume name and routes the pod's `volumes[]` entry through this resource's generated PVC.
- Calling the [KubernetesPersistentVolumeExtensions.WithPersistentVolume(IResourceBuilder<T>, IResourceBuilder<KubernetesPersistentVolumeResource>)](/reference/api/csharp/aspire.hosting.kubernetes/kubernetespersistentvolumeextensions/methods.md#withpersistentvolume-iresourcebuilder-t-iresourcebuilder-kubernetespersistentvolumeresource) overload that takes a mount path. Works for both `ContainerResource` and `ProjectResource`.

Any workload bound to a persistent volume is automatically rendered as a `StatefulSet` rather than a `Deployment` -- Kubernetes requires stable identity and ordered rollout for pods that share named PVCs.

This resource is publish-only. It has no run-mode behavior or dashboard surface.

## Constructors

- [KubernetesPersistentVolumeResource(string, KubernetesEnvironmentResource)](/reference/api/csharp/aspire.hosting.kubernetes/kubernetespersistentvolumeresource/constructors.md#constructor-string-kubernetesenvironmentresource) -- Represents a Kubernetes PersistentVolumeClaim as a first-class resource in the Aspire application model. A persistent volume resource carries the storage class, capacity, access modes, and metadata annotations needed to render a `v1.PersistentVolumeClaim` at publish time. Workloads bind to it with [KubernetesPersistentVolumeExtensions.WithPersistentVolume(IResourceBuilder<T>, IResourceBuilder<KubernetesPersistentVolumeResource>)](/reference/api/csharp/aspire.hosting.kubernetes/kubernetespersistentvolumeextensions/methods.md#withpersistentvolume-iresourcebuilder-t-iresourcebuilder-kubernetespersistentvolumeresource).

## Properties

- [Parent](/reference/api/csharp/aspire.hosting.kubernetes/kubernetespersistentvolumeresource/properties.md#parent) : [KubernetesEnvironmentResource](/reference/api/csharp/aspire.hosting.kubernetes/kubernetesenvironmentresource.md) `get` -- Gets the parent Kubernetes environment resource.

## Examples

```csharp
var k8s = builder.AddKubernetesEnvironment("k8s");

var data = k8s.AddPersistentVolume("data")
    .WithStorageClass("managed-csi")
    .WithCapacity("20Gi")
    .WithAccessMode(PersistentVolumeAccessMode.ReadWriteOnce)
    .WithVolumeAnnotation("volume.beta.kubernetes.io/storage-provisioner", "disk.csi.azure.com");

builder.AddContainer("postgres", "postgres:16")
       .WithVolume("data", "/var/lib/postgresql/data")
       .WithPersistentVolume(data);
```
