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:

1cinst -y draft

Then configure it:

1draft config set registry <registry full name>

Be sure to log on to the Container Registry:

1docker login <registry full name>

or if working with Azure Container Registry:

1az acr login --name <acrName>

Create and prepare the application#

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

1dotnet new mvc
2draft create --pack=csharp -a mvcdraft

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:

1draft up

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

1Draft Up Started: 'netcoredraft': 01CWKAZ79WR6W66PHHR2AFRSGC
2netcoredraft: Building Docker Image: SUCCESS ⚓  (1.0008s)
3netcoredraft: Pushing Docker Image: SUCCESS ⚓  (3.2891s)
4netcoredraft: Releasing Application: SUCCESS ⚓  (2.7629s)
5Inspect the logs with `draft logs 01CWKAZ79WR6W66PHHR2AFRSGC`

To test the application run:

1draft connect

The output should look similar to:

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

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:

1draft delete

Hope it helps!!!