KubernetesPersistentVolumeExtensions
Classstaticnet10.0
Provides extension methods for configuring Kubernetes
KubernetesPersistentVolumeResource resources and binding workloads to them. namespace Aspire.Hosting;
public static class KubernetesPersistentVolumeExtensions{ // ...}10 members
Methods10
Section titled MethodsAddPersistentVolume(IResourceBuilder<KubernetesEnvironmentResource>, string)extensionats exportIResourceBuilder<KubernetesPersistentVolumeResource> Adds a Kubernetes PersistentVolumeClaim resource to the application model as a child of the specified Kubernetes environment. The resource generates a
v1.PersistentVolumeClaim manifest in the Helm chart output at publish time. WithAccessMode(IResourceBuilder<KubernetesPersistentVolumeResource>, PersistentVolumeAccessMode)extensionats exportIResourceBuilder<KubernetesPersistentVolumeResource> Adds an access mode to the PVC's
spec.accessModes. Call multiple times to declare more than one mode. When unset, the environment's KubernetesEnvironmentResource.DefaultStorageReadWritePolicy is used. WithCapacity(IResourceBuilder<KubernetesPersistentVolumeResource>, string)extensionats exportIResourceBuilder<KubernetesPersistentVolumeResource> Sets the requested storage capacity on the PVC's
spec.resources.requests.storage field. WithCapacity(IResourceBuilder<KubernetesPersistentVolumeResource>, IResourceBuilder<ParameterResource>)extensionats exportIResourceBuilder<KubernetesPersistentVolumeResource> Sets the requested storage capacity using a parameter resolved at deploy time.
WithPersistentVolume(IResourceBuilder<T>, IResourceBuilder<KubernetesPersistentVolumeResource>)extensionats exportIResourceBuilder<T> Binds a workload to a Kubernetes
KubernetesPersistentVolumeResource using name matching. The workload must already declare a volume with a matching source name (typically via WithVolume("name", "/path") or an integration helper such as Postgres' WithDataVolume()). The publisher rewrites that volume's pod-spec entry to reference the generated PVC and promotes the workload to a StatefulSet. WithPersistentVolume(IResourceBuilder<T>, IResourceBuilder<KubernetesPersistentVolumeResource>, string, bool)extensionats exportIResourceBuilder<T> Binds a workload to a Kubernetes
KubernetesPersistentVolumeResource and mounts it at the specified path inside the workload's container. Unlike the name-match overload this one creates the underlying mount itself, so it works for workloads that don't already declare a named volume — including ApplicationModel.ProjectResource. WithStorageClass(IResourceBuilder<KubernetesPersistentVolumeResource>, string)extensionats exportIResourceBuilder<KubernetesPersistentVolumeResource> Sets the Kubernetes storage class name on the PVC's
spec.storageClassName. When unset, the cluster's default storage class is used. WithStorageClass(IResourceBuilder<KubernetesPersistentVolumeResource>, IResourceBuilder<ParameterResource>)extensionats exportIResourceBuilder<KubernetesPersistentVolumeResource> Sets the Kubernetes storage class name using a parameter resolved at deploy time.
WithVolumeAnnotation(IResourceBuilder<KubernetesPersistentVolumeResource>, string, string)extensionats exportIResourceBuilder<KubernetesPersistentVolumeResource> Adds a Kubernetes metadata annotation to the generated PVC. These flush to
metadata.annotations on the rendered Kubernetes resource — not Aspire ApplicationModel.IResourceAnnotation instances. Common uses: CSI driver hints, dynamic provisioner parameters, external-secrets selectors, or backup tooling tags. WithVolumeAnnotation(IResourceBuilder<KubernetesPersistentVolumeResource>, string, IResourceBuilder<ParameterResource>)extensionats exportIResourceBuilder<KubernetesPersistentVolumeResource> Adds a Kubernetes metadata annotation with a parameter value resolved at deploy time.