- Published on
- šµ 4 min read
Deploying .NET Aspire Microservices to Kubernetes with Aspir8 CLI and Helm
- Authors
- Name
- Emin Vergil
- @eminvergil
Overview
Introduction
Kubernetes is widely used for modern applications due to its auto-scaling, easy deployment, and cloud-native features. Microsoft is also pushing .NET to be more cloud-native. Recently, they introduced .NET Aspire, a toolset designed to make cloud-native development easier.
What is .NET Aspire?
.NET Aspire is a collection of tools, templates, and packages that help developers build production-ready, observable applications.
While itās not a replacement for Kubernetes, it simplifies the cloud-native experience on your local machine and provides flexible deployment options. For example, you can:
- Use
azd deploy
to deploy your app to Azure. - Use Docker Compose or Docker Swarm.
- Deploy directly to Kubernetes.
In this guide, weāll build a microservice project with .NET Aspire, define microservice relationships, create a Helm chart, and deploy it to Kubernetes.
Prerequisites
Before we begin, make sure you have:
Example Project
For this tutorial, I created a project called Library
. It includes:
- A single API service (
library-api
). - Dependencies: a PostgreSQL database and Redis.
Hereās how the infrastructure is defined in App Host Program.cs
:
var builder = DistributedApplication.CreateBuilder(args);
var redis = builder.AddRedis("redis");
var libraryDb = builder.AddPostgres("postgres")
.WithDataVolume()
.AddDatabase("library");
builder.AddProject<Projects.Library_Api>("library-api")
.WithReference(redis)
.WithReference(libraryDb);
builder.Build().Run();
Deploying to Kubernetes
1 - Set Up a Local Docker Registry InstallĀ Distribution (formerly known as Registry)Ā as a local Docker Hub (Container Registry).
docker run -d -p 6000:5000 --name registry registry:latest
2 - Install aspirate
dotnet tool install -g aspirate
3 - Initialise aspirate
cd Library.AppHost
aspirate init -cr localhost:6000 -ct latest --disable-secrets true --non-interactive
4 - Build and publish the app to the local container registry
aspirate generate --image-pull-policy Always --include-dashboard true --disable-secrets true --non-interactive
5 - Deploy the app to the Kubernetes cluster.
helm upgrade aspire-helm-demo . --install --namespace aspire-demo --create-namespace --wait
6 - Check the services in the Kubernetes cluster.
kubectl get services -n aspire-demo
you can use port-forward
command to open aspire dashboard
Check out the library project here:
You can also check similar posts about .NET Aspire: