콘텐츠로 이동
Docs Try Aspire
Docs Try

Kubernetes integration

이 콘텐츠는 아직 번역되지 않았습니다.

Kubernetes logo

This article is the reference for the Aspire Kubernetes hosting integration. It enumerates the AppHost APIs — with examples for both AppHost.cs and apphost.ts — that you use to model Kubernetes environment resources in your AppHost project. The integration enables you to publish and deploy your Aspire application to any Kubernetes cluster, generating Helm charts from your application model or deploying directly to a cluster using your current kubectl context.

To start building an Aspire app with Kubernetes deployment support, install the 📦 Aspire.Hosting.Kubernetes NuGet package:

Terminal
aspire add kubernetes

Learn more about aspire add in the command reference.

Or, choose a manual installation approach:

C# — AppHost.cs
#:package Aspire.Hosting.Kubernetes@*
XML — AppHost.csproj
<PackageReference Include="Aspire.Hosting.Kubernetes" Version="*" />

After installing the package, add a Kubernetes environment to your AppHost:

C# — AppHost.cs
var builder = DistributedApplication.CreateBuilder(args);
var k8s = builder.AddKubernetesEnvironment("k8s");
var api = builder.AddProject<Projects.MyApi>("api");
builder.Build().Run();

You can configure the generated Helm chart using the WithHelm method, which provides a fluent HelmChartOptions builder:

C# — AppHost.cs
builder.AddKubernetesEnvironment("k8s")
.WithHelm(helm =>
{
helm.WithChartName("my-aspire-app")
.WithChartVersion("1.0.0")
.WithChartDescription("My Aspire application deployed to Kubernetes")
.WithReleaseName("my-release")
.WithNamespace("my-namespace");
});

Helm is the default deployment engine. Call WithHelm only when you need to customize the defaults.

The WithHelm method is the single configuration entry point for Helm chart settings. The available options are:

MethodDescription
WithChartName(string)Sets the Helm chart name (defaults to the application name).
WithChartVersion(string)Sets the Helm chart version. Accepts a literal string or an Aspire parameter.
WithChartDescription(string)Sets the description written into Chart.yaml.
WithReleaseName(string)Sets the Helm release name used during deployment.
WithNamespace(string)Sets the Kubernetes namespace for the deployment.

A vanilla Kubernetes cluster doesn’t know which container registry to use for your application images. Use AddContainerRegistry and WithContainerRegistry to specify a registry that is accessible from both your local machine and from the cluster:

C# — AppHost.cs
var registry = builder.AddContainerRegistry("registry", "myregistry.example.com:5000");
builder.AddKubernetesEnvironment("k8s").WithContainerRegistry(registry);

Use PublishAsKubernetesService to modify the generated Kubernetes resources for individual services:

C# — AppHost.cs
using Aspire.Hosting.Kubernetes.Resources;
builder.AddContainer("service", "nginx")
.PublishAsKubernetesService(resource =>
{
// Scale to 3 replicas
if (resource.Workload is Deployment deployment)
{
deployment.Spec.Replicas = 3;
}
});

The Kubernetes integration supports both aspire publish (generate Helm chart artifacts) and aspire deploy (deploy directly to your current cluster context).

For complete walkthroughs, see Deploy to Kubernetes clusters.