Published on

simplifying microservice deployment with aspire and aspir8

Authors

aspire and aspir8 are powerful tools that leverage kubernetes to make deploying microservices easier for developers across various cloud environments. let's walk through setting up and using these tools.

what you'll need

  1. rancher desktop
  2. .net 8
  3. aspire tooling for .net
  4. aspir8

understanding aspire project structure

an aspire project typically consists of two main parts:

  1. app host: this is where you define how your services interact. it's the blueprint of your application's architecture.

    here is an example:


var builder = DistributedApplication.CreateBuilder(args);

var redis = builder.AddRedis("redis");
var postgres = builder.AddPostgres("postgres");
var rabbitMq = builder.AddRabbitMQ("eventbus");
var mongodb = builder.AddMongoDB("mongo");

var courseDb = mongodb.AddDatabase("coursedb");
var instructorDb = postgres.AddDatabase("instructordb");
var studentDb = postgres.AddDatabase("studentdb");

builder.AddProject<Projects.Course_Api>("course-api")
    .WithReference(redis)
    .WithReference(courseDb)
    .WithReference(rabbitMq);

builder.AddProject<Projects.Instructor_Api>("instructor-api")
    .WithReference(instructorDb)
    .WithReference(rabbitMq);

builder.AddProject<Projects.Student_Api>("student-api")
    .WithReference(redis)
    .WithReference(studentDb)
    .WithReference(rabbitMq);

builder.Build().Run();
  1. service defaults: these are pre-configured settings that add common features like monitoring, logging, and health checks to your services automatically.

deployment steps

1. set up a local docker registry

first, let's create a local docker registry. this saves us from needing to use external registries like docker hub. run this command:

docker run -d -p 5001:5000 --restart always --name registry registry:2

2. initialize aspir8

set up aspir8 with:

aspirate init

when prompted for a default container registry, enter localhost:5001.

3. build your project

build your aspire project using aspir8:

aspirate build

4. generate kubernetes files

create the necessary kubernetes configuration files:

aspirate generate

5. deploy to kubernetes

apply your configuration to deploy your services:

aspirate apply

6. verify your deployment

to check if everything is working:

  1. open the rancher desktop dashboard
  2. go to the "port forwarding" section
  3. forward a port to one of your services
  4. test the service by accessing it through the forwarded port

and that's it! you've successfully deployed your microservices using aspire and aspir8.