KubernetesPersistentVolumeExtensions
Classstaticnet10.0
Provides extension methods for configuring Kubernetes
KubernetesPersistentVolumeResource resources and binding workloads to them. namespace Aspire.Hosting;
public static class KubernetesPersistentVolumeExtensions{ // ...}14 members
Methods14
Section titled MethodsIResourceBuilder<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. IResourceBuilder<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.
WithConfiguration(IResourceBuilder<KubernetesPersistentVolumeResource>, Action<PersistentVolumeClaim>) extensionats exportIResourceBuilder<KubernetesPersistentVolumeResource> Configures the Kubernetes PersistentVolumeClaim generated for the persistent volume.
IResourceBuilder<KubernetesPersistentVolumeResource> Omits
spec.storageClassName from the generated PVC so Kubernetes can assign the cluster's default StorageClass. To request a classless volume, call KubernetesPersistentVolumeExtensions.WithStorageClass with an empty string. WithPersistentVolume(IResourceBuilder<T>, IResourceBuilder<KubernetesPersistentVolumeResource>) extensionats exportIResourceBuilder<T> Binds a workload to a Kubernetes
KubernetesPersistentVolumeResource using name matching. The workload must 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 ignoredIResourceBuilder<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 . WithPersistentVolume(IResourceBuilder<T>, IResourceBuilder<KubernetesPersistentVolumeResource>, string, string, bool) extensionats ignoredIResourceBuilder<T> Binds a workload to a Kubernetes
KubernetesPersistentVolumeResource , mounts it at the specified path when deployed, and exposes the effective storage path through an environment variable. WithPersistentVolumeName(IResourceBuilder<KubernetesPersistentVolumeResource>, string) extensionats exportIResourceBuilder<KubernetesPersistentVolumeResource> Sets the name of the existing PersistentVolume to bind to in the generated PVC's
spec.volumeName . IResourceBuilder<KubernetesPersistentVolumeResource> Sets the Kubernetes storage class name on the PVC's
spec.storageClassName . When unset, the cluster's default storage class is used. An empty string explicitly disables storage class assignment. 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.