इसे छोड़कर कंटेंट पर जाएं
Docs Try Aspire

Deploy to Kubernetes

यह कंटेंट अभी तक आपकी भाषा में उपलब्ध नहीं है।

Kubernetes is a supported deployment target for Aspire applications. By adding the Kubernetes hosting integration to your AppHost, you can use aspire publish to generate a complete set of Helm chart artifacts ready for deployment to any Kubernetes cluster.

For hosting integration setup and configuration, see Kubernetes integration.

To configure your AppHost for Kubernetes, add a Kubernetes environment with AddKubernetesEnvironment:

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

To generate Kubernetes deployment artifacts from your Aspire application, run the aspire publish command:

Generate Kubernetes artifacts
aspire publish -o k8s-artifacts

This command analyzes your application model and produces a complete Helm chart in the specified output directory. The generated chart structure looks like this:

  • Directoryk8s-artifacts/
    • Chart.yaml Chart metadata (name, version, etc.)
    • values.yaml Configurable values for the chart
    • Directorytemplates/
      • Directory<resource>/
        • deployment.yaml Deployment or StatefulSet
        • service.yaml Service for connectivity
        • configmap.yaml Configuration data
        • secret.yaml Sensitive data

The publisher generates the following Kubernetes resources from your application model:

  • Deployments or StatefulSets for your application services
  • Services for network connectivity between resources
  • ConfigMaps for application configuration and connection strings
  • Secrets for sensitive data such as passwords and connection strings
  • Dockerfiles copied into the output directory for container build contexts

After generating artifacts, use Helm to deploy your application to a Kubernetes cluster:

  1. Install the chart to your cluster:

    Install with Helm
    helm install my-app ./k8s-artifacts
  2. For subsequent deployments, upgrade the existing release:

    Upgrade with Helm
    helm upgrade my-app ./k8s-artifacts
  3. Override default values using --set flags or a custom values file:

    Override values
    helm upgrade my-app ./k8s-artifacts \
    --set api.image.repository=myregistry.azurecr.io/api \
    --set api.image.tag=v1.2.0

    Alternatively, create a custom values file for your environment:

    values.production.yaml
    api:
    image:
    repository: myregistry.azurecr.io/api
    tag: v1.2.0
    Deploy with custom values file
    helm upgrade my-app ./k8s-artifacts -f values.production.yaml

The Kubernetes publisher converts Aspire resources to their Kubernetes equivalents:

Aspire resourceKubernetes resource
Project resourcesDeployments or StatefulSets
Container resourcesDeployments or StatefulSets
Connection stringsConfigMaps and Secrets
Environment variablesConfigMaps and Secrets
EndpointsServices
VolumesPersistentVolumes and PersistentVolumeClaims

The publisher generates parameterized Helm values for container image references. If you haven’t specified custom container images, the generated values.yaml contains placeholders that you override at deployment time using --set or a custom values file.

Resource names in Kubernetes must follow DNS naming conventions. The integration automatically normalizes Aspire resource names by:

  • Converting to lowercase
  • Replacing invalid characters with hyphens
  • Ensuring names don’t start or end with hyphens

Use external parameters to configure values that differ between development and production environments.

By default, the Helm chart name is derived from your AppHost project. Configure a custom chart name using WithProperties:

AppHost.cs
var builder = DistributedApplication.CreateBuilder(args);
builder.AddKubernetesEnvironment("k8s")
.WithProperties(k8s =>
{
k8s.HelmChartName = "my-aspire-app";
});

Use the PublishAsKubernetesService callback to modify the generated Kubernetes resources for individual services. This provides fully typed access to the Kubernetes object model:

AppHost.cs
var builder = DistributedApplication.CreateBuilder(args);
builder.AddContainer("service", "nginx")
.WithEnvironment("ORIGINAL_ENV", "value")
.PublishAsKubernetesService(resource =>
{
// Customize the generated Kubernetes resource
});

If your application can’t find connection strings at runtime, verify that the generated ConfigMaps and Secrets are correctly mounted as environment variables in your pod specifications. Check that the resource names in your Helm values match the expected connection string names.

Kubernetes Secrets store values as base64-encoded strings. Verify that your Secrets are properly encoded and that the generated templates reference them correctly. Use kubectl get secret <name> -o yaml to inspect Secret contents.

In Kubernetes, services discover each other using the cluster’s built-in DNS. A service named api is reachable at api.<namespace>.svc.cluster.local. The generated Helm charts configure service references automatically using Kubernetes-native DNS resolution.