# KubernetesPersistentVolumeResource Constructors

- Package: [Aspire.Hosting.Kubernetes](/reference/api/csharp/aspire.hosting.kubernetes.md)
- Type: [KubernetesPersistentVolumeResource](/reference/api/csharp/aspire.hosting.kubernetes/kubernetespersistentvolumeresource.md)
- Kind: `Constructors`
- Members: `1`

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

<a id="constructor"></a>
<a id="constructor-string-kubernetesenvironmentresource"></a>

## KubernetesPersistentVolumeResource(string, KubernetesEnvironmentResource)

- Name: `Constructor(string, KubernetesEnvironmentResource)`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/69db530a4816698cf1d5fa4557933e0ac4f127c6/src/Aspire.Hosting.Kubernetes/KubernetesPersistentVolumeResource.cs#L67-L100)

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

```csharp
public sealed class KubernetesPersistentVolumeResource
{
    public KubernetesPersistentVolumeResource(
        string name,
        KubernetesEnvironmentResource environment)
    {
        // ...
    }
}
```

## Parameters

- `name` (`string`)
  The name of the persistent volume resource. Used as the generated `PersistentVolumeClaim.metadata.name` after lower-casing.
- `environment` ([KubernetesEnvironmentResource](/reference/api/csharp/aspire.hosting.kubernetes/kubernetesenvironmentresource.md))
  The parent Kubernetes environment resource.

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

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