DEV Community

Carlos Mendible
Carlos Mendible

Posted on • Originally published at carlos.mendible.com on

Develop and build ASP.NET Core applications to run on Kubernetes with Draft

You start developing an ASP.NET Core application to run it in Kubernetes and suddenly you find yourself creating a docker file, building an image, pushing the image to a registry, creating both a deployment and a service definition for Kubernetes and you wonder if there is a tool out there to help you streamline the whole process.

Meet Draft a tool that will not only help you create the artifacts needed to build and run applications in Kubernetes but to also build the container image and deploy it.

Prerequisites:

  1. A Kubernetes cluster and the kubectl CLI tool
  2. Installation of Helm on your Kubernetes cluster
  3. A Container Registry

Install and Configure Draft

To install Draft I run the following command:

cinst -y draft
Enter fullscreen mode Exit fullscreen mode

Then configure it:

draft config set registry <registry full name>
Enter fullscreen mode Exit fullscreen mode

Be sure to log on to the Container Registry:

docker login <registry full name>
Enter fullscreen mode Exit fullscreen mode

or if working with Azure Container Registry:

az acr login --name <acrName>
Enter fullscreen mode Exit fullscreen mode

Create and prepare the application

Creat an ASP.NET Core MVC application and create the artifacts with Draft:

dotnet new mvc
draft create --pack=csharp -a mvcdraft
Enter fullscreen mode Exit fullscreen mode

Note that I’ve specified two parameters:

  • pack to tell draft that we are using C# as the language.
  • a to specify the name of the Helm release we will run on Kubernetes

Deploy and test your application

Run the following command to build the container image and then deploy the application to Kubernetes:

draft up
Enter fullscreen mode Exit fullscreen mode

The first time you run the command it will take a while. The output should look similar to this:

Draft Up Started: 'netcoredraft': 01CWKAZ79WR6W66PHHR2AFRSGC
netcoredraft: Building Docker Image: SUCCESS ⚓ (1.0008s)
netcoredraft: Pushing Docker Image: SUCCESS ⚓ (3.2891s)
netcoredraft: Releasing Application: SUCCESS ⚓ (2.7629s)
Inspect the logs with `draft logs 01CWKAZ79WR6W66PHHR2AFRSGC`
Enter fullscreen mode Exit fullscreen mode

To test the application run:

draft connect
Enter fullscreen mode Exit fullscreen mode

The output should look similar to:

Connect to netcoredraft:80 on localhost:50998
[netcoredraft]: No XML encryptor configured. Key {ea9dac08-e7af-468c-9e00-cbe38ab40fa8} may be persisted to storage in unencrypted form.
[netcoredraft]: Hosting environment: Production
[netcoredraft]: Content root path: /app
[netcoredraft]: Now listening on: http://[::]:80
[netcoredraft]: Application started. Press Ctrl+C to shut down.
Enter fullscreen mode Exit fullscreen mode

Browse to the url shown in the output (i.e. http://localhost:50998) and you should be good to go!!!

Cleaning up

Once you finish your tests you can cleanup with the following command:

draft delete
Enter fullscreen mode Exit fullscreen mode

Hope it helps!!!

Top comments (0)