Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<SuppressFinalPackageVersion>true</SuppressFinalPackageVersion>
<EnablePackageValidation>false</EnablePackageValidation>
<EnableAspireIntegrationAnalyzers>true</EnableAspireIntegrationAnalyzers>
<PackageTags>aspire integration hosting azure kubernetes aks</PackageTags>
<Description>Azure Kubernetes Service (AKS) resource types for Aspire.</Description>
<PackageIconFullPath>$(SharedDir)Azure_256x.png</PackageIconFullPath>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Diagnostics.CodeAnalysis;
using Aspire.Hosting.ApplicationModel;
using Aspire.Hosting.Azure.Kubernetes;
using Aspire.Hosting.Kubernetes;

namespace Aspire.Hosting;

/// <summary>
/// Provides extension methods for adding Kubernetes persistent volumes to an
/// <see cref="AzureKubernetesEnvironmentResource"/>.
/// </summary>
[Experimental("ASPIRECOMPUTE002", UrlFormat = "https://aka.ms/aspire/diagnostics/{0}")]
public static class AzureKubernetesPersistentVolumeExtensions
{
/// <summary>
/// Adds a Kubernetes PersistentVolumeClaim resource to the application model for the
/// specified AKS environment.
/// </summary>
/// <ats-summary>Adds a Kubernetes PersistentVolumeClaim resource to an AKS environment</ats-summary>
/// <param name="builder">The AKS environment resource builder.</param>
/// <param name="name">The name of the persistent volume resource.</param>
/// <returns>A builder for the new <see cref="KubernetesPersistentVolumeResource"/>.</returns>
/// <ats-returns>The resource builder.</ats-returns>
/// <remarks>
/// <para>
/// The persistent volume is associated with the AKS environment's underlying Kubernetes
/// environment and generates a <c>v1.PersistentVolumeClaim</c> in the Helm chart output.
/// </para>
/// <para>
/// When no storage class is configured, the generated claim omits
/// <c>spec.storageClassName</c> so the cluster's default storage class is used. A standard
/// AKS cluster dynamically provisions an Azure managed disk for such claims. Use
/// <see cref="KubernetesPersistentVolumeExtensions.WithStorageClass(IResourceBuilder{KubernetesPersistentVolumeResource}, string)"/>
/// to select a different storage class explicitly.
/// </para>
/// </remarks>
/// <ats-remarks />
/// <example>
/// <code>
/// var aks = builder.AddAzureKubernetesEnvironment("aks");
///
/// var data = aks.AddPersistentVolume("data")
/// .WithCapacity("20Gi");
///
/// builder.AddProject&lt;Projects.Api&gt;("api")
/// .WithPersistentVolume(data, "/data");
/// </code>
/// </example>
[AspireExport]
Comment thread
mitchdenny marked this conversation as resolved.
public static IResourceBuilder<KubernetesPersistentVolumeResource> AddPersistentVolume(
this IResourceBuilder<AzureKubernetesEnvironmentResource> builder,
[ResourceName] string name)
{
ArgumentNullException.ThrowIfNull(builder);
ArgumentException.ThrowIfNullOrEmpty(name);

var k8sEnvBuilder = builder.ApplicationBuilder.CreateResourceBuilder(builder.Resource.KubernetesEnvironment);
return k8sEnvBuilder.AddPersistentVolume(name);
}
}
24 changes: 24 additions & 0 deletions src/Aspire.Hosting.Azure.Kubernetes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,30 @@ const myService = await builder.addNodeApp("myService", "../my-service", "server
.withComputeEnvironment(aks);
```

### Persistent volumes

Add a persistent volume to the AKS environment and mount it into a workload:

**C#**

```csharp
var data = aks.AddPersistentVolume("data")
.WithCapacity("20Gi");

myService.WithPersistentVolume(data, "/data");
```

**TypeScript**

```typescript
const data = await aks.addPersistentVolume("data");
await data.withCapacity("20Gi");

await myService.withKubernetesPersistentVolumeMount(data, "/data");
```

When no storage class is specified, the generated claim uses the cluster's default storage class. A standard AKS cluster dynamically provisions an Azure managed disk. To request Premium SSD storage explicitly, call `WithStorageClass("managed-csi-premium")` in C# or `withStorageClass("managed-csi-premium")` in TypeScript.

## Additional documentation

* https://aspire.dev/integrations/gallery/
Expand Down
Loading
Loading