Gå til indhold
Docs Try Aspire

Kubernetes integration

Dette indhold er ikke tilgængeligt i dit sprog endnu.

Kubernetes logo

The Aspire Kubernetes hosting integration enables you to generate Kubernetes deployment manifests from your Aspire application model. This integration allows you to define your application’s infrastructure and deployment configuration using the familiar Aspire AppHost and then publish it as Kubernetes YAML manifests for deployment to any Kubernetes cluster.

To get started with the Aspire Kubernetes hosting integration, install the 📦 Aspire.Hosting.Kubernetes NuGet package in the AppHost project:

Aspire CLI — Tilføj Aspire.Hosting.Kubernetes-pakke
aspire add kubernetes

Aspire CLI er interaktiv; vælg det passende søgeresultat når du bliver spurgt:

Aspire CLI — Eksempel output
Select an integration to add:
> kubernetes (Aspire.Hosting.Kubernetes)
> Other results listed as selectable options...

After installing the package, add a Kubernetes environment to your AppHost project using the AddKubernetesEnvironment method:

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

Configure Kubernetes environment properties

Section titled “Configure Kubernetes environment properties”

You can customize the Kubernetes environment using the WithProperties method:

C# — AppHost.cs
var builder = DistributedApplication.CreateBuilder(args);
var api = builder.AddProject<Projects.MyApi>("api");
builder.AddKubernetesEnvironment("k8s")
.WithProperties(k8s =>
{
k8s.HelmChartName = "my-aspire-app";
});
builder.Build().Run();

The WithProperties method allows you to configure various aspects of the Kubernetes deployment, including the Helm chart name that will be used for generating the Kubernetes resources.

For a complete guide on generating Kubernetes Helm charts, deploying with Helm, resource mappings, and troubleshooting — see Deploy to Kubernetes.