Deploying distributed applications to Kubernetes involves more than building container images. Developers must also configure deployments, services, environment variables, secrets, networking, storage, and other Kubernetes resources. Managing these configurations manually can become difficult as an application grows.
.NET Aspire simplifies application development by providing a code-first model for defining services and their dependencies. Its Kubernetes hosting integration extends this model to deployment by generating Helm charts from the application configuration.
Instead of maintaining every Kubernetes manifest separately, developers can describe application resources in the Aspire AppHost and use the Aspire CLI to generate deployment artifacts. These artifacts can then be reviewed, customized, and deployed to an existing Kubernetes cluster.
This article explains how to configure Kubernetes deployment in .NET Aspire, generate Helm charts, customize chart settings, and deploy an application to a Kubernetes cluster.
What Is Helm?
Helm is a package manager for Kubernetes. It helps developers package, configure, install, upgrade, and manage Kubernetes applications.
A Helm chart contains templates and configuration files that describe the Kubernetes resources required by an application. These resources can include Deployments, Services, ConfigMaps, Secrets, and other Kubernetes objects.
A typical Helm chart has the following structure:
my-application/
│
├── Chart.yaml
├── values.yaml
│
└── templates/
├── deployment.yaml
├── service.yaml
├── configmap.yaml
└── ingress.yaml
Chart.yaml contains chart metadata such as its name, version, and description.
The values.yaml file contains configurable values used by the templates. For example, developers can define container image names, replica counts, ports, and resource settings.
The templates directory contains Kubernetes resource templates. Helm combines these templates with the supplied values to generate the final Kubernetes manifests.
Helm makes it easier to maintain application deployment configurations across development, testing, staging, and production environments.
What Is the .NET Aspire Kubernetes Integration?
.NET Aspire provides the Aspire.Hosting.Kubernetes integration for modeling and deploying application resources to Kubernetes.
The integration connects the Aspire application model with Kubernetes deployment workflows. Developers define application resources in the AppHost, configure a Kubernetes environment, and use Aspire publishing or deployment commands to generate and apply Helm charts.
The integration supports two main workflows:
Aspire translates the application model into Kubernetes resources. For example, project resources and container resources can become Deployments or StatefulSets, endpoints become Services, and environment variables and connection strings are represented through ConfigMaps and Secrets.
This approach reduces the need to maintain separate Kubernetes definitions for every application resource.
Prerequisites
Before generating Helm charts with Aspire, prepare your development environment.
You need the following tools:
The current Kubernetes integration documentation requires Helm 4.2.0 or later. Keep Helm and the Aspire CLI updated according to the requirements of the Aspire version you are using.
You can verify the installed tools with the following commands:
dotnet --version
aspire --version
helm version
kubectl version --client
You also need a Kubernetes cluster. It can be a local development cluster or a remote cluster managed by your organization.
Check the active Kubernetes context:
kubectl config current-context
This command helps confirm which cluster kubectl is configured to access. Always verify the context before deploying because Aspire uses the current Kubernetes context for the existing-cluster deployment workflow.
Creating an Aspire Application
If you already have an Aspire solution, you can use its existing AppHost project. Otherwise, create a new Aspire application using the available project templates or CLI.
For this example, consider an application with the following structure:
AspireKubernetesDemo/
│
├── AspireKubernetesDemo.AppHost/
│ └── AppHost.cs
│
├── AspireKubernetesDemo.Api/
│ ├── Program.cs
│ └── Controllers/
│
└── AspireKubernetesDemo.ServiceDefaults/
The ASP.NET Core API contains the application logic, while the AppHost defines the application resources and their relationships.
The goal is to generate a Helm chart that contains the Kubernetes resources required to deploy this application.
Installing the Kubernetes Hosting Integration
Open a terminal in the AppHost project directory and run:
aspire add kubernetes
This command adds the Aspire.Hosting.Kubernetes integration to the AppHost configuration.
You can also install the NuGet package manually:
dotnet add package Aspire.Hosting.Kubernetes
Make sure the package version is compatible with the Aspire version used by your solution.
After installing the integration, you can configure a Kubernetes environment in the AppHost.
Configuring Kubernetes in AppHost
Open AppHost.cs and register a Kubernetes environment using AddKubernetesEnvironment.
The following example shows a basic configuration:
var builder = DistributedApplication.CreateBuilder(args);
var k8s = builder.AddKubernetesEnvironment("k8s");
var api = builder.AddProject<Projects.AspireKubernetesDemo_Api>(
"api");
builder.Build().Run();
The AddKubernetesEnvironment method adds a Kubernetes environment to the Aspire application model.
The AddProject method registers the ASP.NET Core API as an application resource.
The k8s variable represents the Kubernetes environment. You can use it when an application has multiple compute environments and you need to assign a resource to a specific environment.
For a simple application with one Kubernetes environment, Aspire can use the configured environment without requiring additional resource assignment.
This configuration provides the foundation for generating a Helm chart from the application model.
Configuring Helm Chart Options
Aspire uses Helm as the default deployment engine for its Kubernetes integration. You only need to configure additional Helm settings when the default values do not meet your requirements.
The WithHelm method provides a configuration builder for customizing the generated chart.
Update the AppHost configuration:
var builder = DistributedApplication.CreateBuilder(args);
builder.AddKubernetesEnvironment("k8s")
.WithHelm(helm =>
{
helm.WithChartName("aspire-kubernetes-demo")
.WithChartVersion("1.0.0")
.WithChartDescription(
"Kubernetes deployment for Aspire application")
.WithReleaseName("aspire-demo")
.WithNamespace("production");
});
var api = builder.AddProject<Projects.AspireKubernetesDemo_Api>(
"api");
builder.Build().Run();
The configuration defines several Helm chart properties.
Method | Purpose |
|---|
WithChartName | Sets the generated Helm chart name |
WithChartVersion | Defines the chart version |
WithChartDescription | Adds a description to Chart.yaml |
WithReleaseName | Sets the Helm release name |
WithNamespace | Specifies the Kubernetes namespace |
The chart name identifies the generated package, while the release name identifies the installed Helm release.
The namespace determines where the application resources are deployed in Kubernetes.
These values help maintain consistent naming across deployment environments. Avoid using a production namespace for local testing unless that is intentional.
Generating Helm Charts With Aspire
After configuring the AppHost, you can generate deployment artifacts using the Aspire CLI.
Run the following command from the solution or AppHost directory:
aspire publish -o ./k8s-manifests
The publish command evaluates the Aspire application model and generates the deployment artifacts for the configured Kubernetes environment.
The output directory contains the generated Helm chart and its associated configuration files.
The exact directory structure and generated resources depend on the application model and the Aspire version.
A simplified chart structure may look like this:
k8s-manifests/
│
└── aspire-kubernetes-demo/
├── Chart.yaml
├── values.yaml
└── templates/
├── deployment.yaml
├── service.yaml
└── configmap.yaml
Chart.yaml contains the chart metadata configured through WithHelm.
The values.yaml file contains the configurable deployment values. The templates directory contains the Kubernetes resource definitions generated from the Aspire application model.
Review the generated files before deploying them. Publishing is an important opportunity to inspect container images, configuration values, service definitions, and other deployment settings.
Understanding How Aspire Maps Resources to Kubernetes
One of the main benefits of the Kubernetes integration is that Aspire translates its application model into Kubernetes-native resources.
The mapping depends on the resource type and its configuration.
Aspire resource | Kubernetes resource |
|---|
Project resources | Deployments or StatefulSets |
Container resources | Deployments or StatefulSets |
Connection strings | ConfigMaps and Secrets |
Environment variables | ConfigMaps and Secrets |
Endpoints | Services |
Volumes | PersistentVolumes and PersistentVolumeClaims |
For example, an ASP.NET Core API registered in the AppHost can become a Kubernetes workload. Its configured endpoint can become a Kubernetes Service.
Similarly, connection strings and environment variables are represented through Kubernetes configuration resources.
This approach allows developers to describe the application in Aspire rather than manually writing every Kubernetes resource definition.
However, generated resources should still be reviewed against the application's operational requirements. For example, production applications may need custom probes, resource limits, storage settings, ingress configuration, or scheduling rules.
Configuring Container Registry Information
Kubernetes clusters need access to the container images used by application workloads.
If an image is stored in a private container registry, the generated chart must contain the correct registry-qualified image name.
Aspire supports container registry configuration through its application model.
For example:
var builder = DistributedApplication.CreateBuilder(args);
var registry = builder.AddContainerRegistry(
"registry",
"registry.example.com",
"apps");
var api = builder.AddProject<Projects.AspireKubernetesDemo_Api>(
"api")
.WithContainerRegistry(registry);
builder.AddKubernetesEnvironment("k8s");
builder.Build().Run();
The registry configuration associates the application resource with a container registry.
During publishing, Aspire can include the registry-qualified image name in the generated Helm chart.
For example, the generated values.yaml may contain an image reference similar to this:
parameters:
api:
api_image: "registry.example.com/apps/api:latest"
The actual image name depends on the configured registry and publishing options.
A Kubernetes cluster must also have permission to pull images from a private registry. Configure the required image pull credentials or workload identity according to your registry and cluster setup.
Do not assume that defining a registry in the AppHost automatically grants the cluster access to private images.
Deploying the Helm Chart to Kubernetes
After publishing the chart, you can deploy it using Helm.
First, review the generated chart and confirm that the required image references and configuration values are available.
Then install the chart:
helm install aspire-demo ./k8s-manifests/aspire-kubernetes-demo \
--namespace production \
--create-namespace
The release name and chart path should match the generated chart configuration.
If the namespace does not exist, the create-namespace option allows Helm to create it.
You can check the release:
helm list -n production
Check the Kubernetes workloads:
kubectl get deployments -n production
Check the services:
kubectl get services -n production
To inspect application pods:
kubectl get pods -n production
These commands help confirm whether Kubernetes created the expected resources and whether the application workloads are running.
Using Aspire Deploy Instead of Manual Helm Installation
You do not always need to execute Helm commands manually.
Aspire also provides the deploy command for deploying an application to the current Kubernetes context.
Run:
aspire deploy
Aspire uses the configured Kubernetes environment, generates the required deployment artifacts, and invokes Helm to install or upgrade the application.
The deployment process uses the current kubectl context. Therefore, verify the active cluster and namespace configuration before running the command.
The difference between publishing and deploying is important:
Command | Purpose |
|---|
aspire publish | Generates deployment artifacts, including Helm charts |
aspire deploy | Deploys the application to the configured target |
Use publishing when you want to review the generated artifacts, store them as build outputs, or deploy through an existing CI/CD pipeline.
Use deploying when you want Aspire to execute the deployment workflow directly.
For production environments, many teams prefer publishing artifacts in CI and applying them through a controlled release process.
Customizing Kubernetes Resources
Generated Helm charts provide a starting point, but some applications need Kubernetes resources that are not represented directly by the default Aspire resource model.
Examples include:
Custom ConfigMaps.
Additional Kubernetes resources.
Certificate resources.
Organization-specific custom resource definitions.
Additional networking configuration.
The Kubernetes integration supports adding custom Kubernetes resources to the generated chart.
In C# AppHost projects, additional resources can be added through the Kubernetes resource model and the AdditionalResources collection of the relevant resource configuration.
This approach is useful when an application depends on Kubernetes features that require custom resource definitions.
For example, an organization might use cert-manager to manage TLS certificates. The application deployment may need a Certificate resource alongside its normal workloads.
Custom resources should be added only when the application requires them. Keep the AppHost configuration understandable and avoid duplicating resources that Aspire already generates.
Publish vs Deploy to Kubernetes
Although both commands are part of the Aspire deployment workflow, they solve different problems.
Area | Publish | Deploy |
|---|
Main purpose | Generate deployment artifacts | Execute deployment |
Helm chart generation | Yes | Yes, as part of the workflow |
Cluster interaction | Not required for chart generation | Uses the configured cluster context |
CI/CD usage | Useful for artifact-based pipelines | Useful for direct deployment workflows |
Manual review | Review artifacts before deployment | Deployment is performed by Aspire |
For an existing Kubernetes cluster, publishing generates Helm charts that can be applied using Helm or a CI/CD pipeline. Deploying uses the current kubectl context and Helm to install or upgrade the application.
Aspire also provides a separate Azure Kubernetes Service deployment target. That workflow can provision Azure infrastructure, including the cluster and container registry, in addition to deploying the application.
Do not confuse deploying to an existing Kubernetes cluster with provisioning a new AKS environment. They are related workflows, but their infrastructure responsibilities are different.
Best Practices for Generating Helm Charts With Aspire
Keep the AppHost configuration organized
The AppHost should describe application resources and their relationships clearly. Avoid adding unrelated configuration or application business logic to the orchestration project.
Review generated charts before deployment
Always inspect Chart.yaml, values.yaml, and the generated templates. Confirm that the image names, ports, environment variables, and Kubernetes resources match the application requirements.
Separate environment-specific values
Development, staging, and production environments may require different namespaces, image tags, resource limits, and configuration values.
Keep environment-specific settings outside the application source code and manage them through appropriate deployment configuration.
Protect secrets
Connection strings and sensitive configuration should not be committed to source control as plain text. Use secure parameter handling and Kubernetes Secrets or an external secret management solution.
Use versioned container images
Avoid relying on the latest image tag for controlled production deployments. Use immutable or uniquely versioned image tags so that a deployment can be traced to a specific application build.
Validate the Kubernetes context
Before running aspire deploy or Helm commands, confirm the active Kubernetes context and target namespace. This helps prevent accidental deployments to the wrong cluster.
Integrate publishing into CI/CD
Use aspire publish to generate deployment artifacts as part of the build process. Review and promote those artifacts through controlled deployment stages rather than generating different configurations manually for every environment.
Common Mistakes and Troubleshooting
Problem | Possible cause | What to check |
|---|
Aspire cannot generate Helm charts | Kubernetes integration is missing | Verify the Aspire.Hosting.Kubernetes package |
Helm command fails | Helm is missing or incompatible | Check the installed Helm version |
Deployment cannot connect to a cluster | Incorrect kubectl context | Run kubectl config current-context |
Pod cannot pull its image | Private registry access is missing | Verify image pull credentials and image names |
Application endpoint is unavailable | Service or endpoint configuration is incorrect | Inspect generated Service and Deployment resources |
Configuration is missing | Incorrect environment or connection string setup | Review generated ConfigMaps and Secrets |
Helm installation fails | Invalid chart configuration or conflicting release | Run Helm validation and inspect the release status |
When troubleshooting, start by reviewing the Aspire publishing output. Then inspect the generated chart and use kubectl and Helm commands to identify whether the problem is related to image access, resource creation, configuration, or application startup.
Advantages and Disadvantages
Advantages
Generates Helm charts from the Aspire application model.
Reduces manual Kubernetes manifest maintenance.
Supports centralized application configuration through AppHost.
Maps application resources to Kubernetes-native resources.
Supports both artifact publishing and direct deployment.
Provides Helm chart customization options.
Fits into existing Kubernetes and CI/CD workflows.
Disadvantages
Requires knowledge of Kubernetes and Helm for production troubleshooting.
Generated charts may need customization for advanced deployment requirements.
Private registry access and secrets still require proper configuration.
Different deployment environments may require additional configuration.
The generated output must be reviewed before production use.
Conclusion
.NET Aspire makes Kubernetes deployment more manageable by connecting the application model defined in AppHost with Helm-based deployment workflows.
With the Aspire.Hosting.Kubernetes integration, developers can configure a Kubernetes environment, customize Helm chart metadata, generate deployment artifacts, and deploy applications to existing Kubernetes clusters.
The main advantage is that developers can describe application resources in one place and allow Aspire to generate the corresponding Kubernetes resources. This reduces repetitive configuration work and provides a consistent approach to local development, publishing, and deployment.
For teams already using .NET Aspire, the Kubernetes integration provides a practical way to move from application development to Kubernetes deployment while retaining control over the generated Helm charts and production release process.
Join the conversation! Your thoughts help the community grow.