KubernetesPersistentVolumeResource
Classsealednet10.0
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 . 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>{ // ...}ResourceIResourceIResourceWithParentIResourceWithParent<KubernetesEnvironmentResource>
Remarks
Section titled RemarksBind a workload to the volume by either:
- Adding a matching
Withon a container resource and callingVolume ("name", "/mount/ path") With. The publisher matches by volume name and routes the pod'sPersistent Volume (volume) volumes[]entry through this resource's generated PVC. - Calling the
Kubernetesoverload that takes a mount path. Works for bothPersistent Volume Extensions. With Persistent Volume ContainerandResource Project.Resource - Calling the
Kubernetesoverload that also sets an environment variable. Projects and executables receive a local persistent path in run mode and the deployed mount path in publish mode.Persistent Volume Extensions. With Persistent Volume
Any workload bound to a persistent volume is automatically rendered as a Stateful rather than a Deployment — Kubernetes requires stable identity and ordered rollout for pods that share named PVCs.
This resource is publish-only and has no dashboard surface. The environment-variable binding overload provides run-mode storage without adding the volume resource to the local application model.
Constructors1
Section titled Constructors 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 . Properties1
Section titled PropertiesView all properties
Examples
Section titled Examplesvar 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);