Skip to content
Docs Try Aspire
Docs Try

KubernetesEnvironmentExtensions Methods

Class Methods 7 members
Provides extension methods for adding Kubernetes environment resources to the application model.
AddKubernetesEnvironment(IDistributedApplicationBuilder, string) Section titled AddKubernetesEnvironment(IDistributedApplicationBuilder, string) extension IResourceBuilder<KubernetesEnvironmentResource>
Adds a Kubernetes environment to the application model.
public static class KubernetesEnvironmentExtensions
{
public static IResourceBuilder<KubernetesEnvironmentResource> AddKubernetesEnvironment(
this IDistributedApplicationBuilder builder,
string name)
{
// ...
}
}
builder IDistributedApplicationBuilder The Hosting.IDistributedApplicationBuilder.
name string The name of the Kubernetes environment resource.
IResourceBuilder<KubernetesEnvironmentResource> A reference to the ApplicationModel.IResourceBuilder`1.
AddNodePool(IResourceBuilder<KubernetesEnvironmentResource>, string) Section titled AddNodePool(IResourceBuilder<KubernetesEnvironmentResource>, string) extension IResourceBuilder<KubernetesNodePoolResource>
Adds a named node pool to the Kubernetes environment.
public static class KubernetesEnvironmentExtensions
{
public static IResourceBuilder<KubernetesNodePoolResource> AddNodePool(
this IResourceBuilder<KubernetesEnvironmentResource> builder,
string name)
{
// ...
}
}
builder IResourceBuilder<KubernetesEnvironmentResource> The Kubernetes environment resource builder.
name string The name of the node pool. This value is used as the nodeSelector value.
IResourceBuilder<KubernetesNodePoolResource> A reference to the ApplicationModel.IResourceBuilder`1 for the new node pool.
For vanilla Kubernetes, this creates a named reference to an existing node pool. For managed Kubernetes services (e.g., AKS), the cloud-specific AddNodePool overload provisions the pool with additional configuration such as VM size and autoscaling. Use KubernetesEnvironmentExtensions.WithNodePool to schedule workloads on the returned node pool.
var k8s = builder.AddKubernetesEnvironment("k8s");
var gpuPool = k8s.AddNodePool("gpu");
builder.AddProject<MyApi>()
.WithComputeEnvironment(k8s)
.WithNodePool(gpuPool);
WithDashboard(IResourceBuilder<KubernetesEnvironmentResource>, bool) Section titled WithDashboard(IResourceBuilder<KubernetesEnvironmentResource>, bool) extension IResourceBuilder<KubernetesEnvironmentResource>
Enables the Aspire dashboard for telemetry visualization in this Kubernetes environment.
public static class KubernetesEnvironmentExtensions
{
public static IResourceBuilder<KubernetesEnvironmentResource> WithDashboard(
this IResourceBuilder<KubernetesEnvironmentResource> builder,
bool enabled = true)
{
// ...
}
}
builder IResourceBuilder<KubernetesEnvironmentResource> The Kubernetes environment resource builder.
enabled bool optional Whether to enable the dashboard. Default is true.
IResourceBuilder<KubernetesEnvironmentResource> A reference to the ApplicationModel.IResourceBuilder`1.
When enabled, an Aspire Dashboard container is deployed alongside the application resources in the Kubernetes cluster. All resources with OTLP telemetry support are automatically configured to send telemetry data to the dashboard.
WithDashboard(IResourceBuilder<KubernetesEnvironmentResource>, Action<IResourceBuilder<KubernetesAspireDashboardResource>>) Section titled WithDashboard(IResourceBuilder<KubernetesEnvironmentResource>, Action<IResourceBuilder<KubernetesAspireDashboardResource>>) extension IResourceBuilder<KubernetesEnvironmentResource>
Configures the dashboard properties for this Kubernetes environment.
public static class KubernetesEnvironmentExtensions
{
public static IResourceBuilder<KubernetesEnvironmentResource> WithDashboard(
this IResourceBuilder<KubernetesEnvironmentResource> builder,
Action<IResourceBuilder<KubernetesAspireDashboardResource>> configure)
{
// ...
}
}
builder IResourceBuilder<KubernetesEnvironmentResource> The Kubernetes environment resource builder.
configure Action<IResourceBuilder<KubernetesAspireDashboardResource>> A method that can be used for customizing the dashboard resource.
IResourceBuilder<KubernetesEnvironmentResource> A reference to the ApplicationModel.IResourceBuilder`1.
Use this overload to customize the dashboard container, for example to set a specific host port or enable forwarded headers for ingress access.
WithHelm(IResourceBuilder<KubernetesEnvironmentResource>, Action<HelmChartOptions>) Section titled WithHelm(IResourceBuilder<KubernetesEnvironmentResource>, Action<HelmChartOptions>) extension IResourceBuilder<KubernetesEnvironmentResource>
Configures the Kubernetes environment to deploy using Helm charts.
public static class KubernetesEnvironmentExtensions
{
public static IResourceBuilder<KubernetesEnvironmentResource> WithHelm(
this IResourceBuilder<KubernetesEnvironmentResource> builder,
Action<HelmChartOptions>? configure = null)
{
// ...
}
}
builder IResourceBuilder<KubernetesEnvironmentResource> The Kubernetes environment resource builder.
configure Action<HelmChartOptions> optional An optional callback to configure Helm chart settings such as namespace, release name, and chart version.
IResourceBuilder<KubernetesEnvironmentResource> A reference to the ApplicationModel.IResourceBuilder`1.
Helm is the default deployment engine. Call this method to customize Helm-specific settings.

Configure Helm deployment with custom settings:

builder.AddKubernetesEnvironment("k8s")
.WithHelm(helm =>
{
helm.WithNamespace("my-namespace");
helm.WithReleaseName("my-release");
helm.WithChartVersion("1.0.0");
});
WithNodePool(IResourceBuilder<T>, IResourceBuilder<KubernetesNodePoolResource>) Section titled WithNodePool(IResourceBuilder<T>, IResourceBuilder<KubernetesNodePoolResource>) extension IResourceBuilder<T>
Schedules a compute resource's workload on the specified Kubernetes node pool. This translates to a Kubernetes nodeSelector in the pod specification targeting the named node pool.
public static class KubernetesEnvironmentExtensions
{
public static IResourceBuilder<T> WithNodePool<T>(
this IResourceBuilder<T> builder,
IResourceBuilder<KubernetesNodePoolResource> nodePool)
{
// ...
}
}
builder IResourceBuilder<T> The resource builder.
nodePool IResourceBuilder<KubernetesNodePoolResource> The node pool to schedule the workload on.
IResourceBuilder<T> A reference to the ApplicationModel.IResourceBuilder`1 for chaining.
var k8s = builder.AddKubernetesEnvironment("k8s");
var gpuPool = k8s.AddNodePool("gpu");
builder.AddProject<MyApi>()
.WithComputeEnvironment(k8s)
.WithNodePool(gpuPool);
WithProperties(IResourceBuilder<KubernetesEnvironmentResource>, Action<KubernetesEnvironmentResource>) Section titled WithProperties(IResourceBuilder<KubernetesEnvironmentResource>, Action<KubernetesEnvironmentResource>) extension IResourceBuilder<KubernetesEnvironmentResource>
Allows setting the properties of a Kubernetes environment resource.
public static class KubernetesEnvironmentExtensions
{
public static IResourceBuilder<KubernetesEnvironmentResource> WithProperties(
this IResourceBuilder<KubernetesEnvironmentResource> builder,
Action<KubernetesEnvironmentResource> configure)
{
// ...
}
}
builder IResourceBuilder<KubernetesEnvironmentResource> The Kubernetes environment resource builder.
configure Action<KubernetesEnvironmentResource> A method that can be used for customizing the KubernetesEnvironmentResource.
IResourceBuilder<KubernetesEnvironmentResource> A reference to the ApplicationModel.IResourceBuilder`1.