Migrating .NET Core applications to the cloud with Stacksmith. Part 2: Packaging for Azure and Kubernetes

Published on July 23, 2018
.net core
Wojciech Kocjan

Wojciech Kocjan

Share this article

In this post I walk you through the process of packaging a .NET Core application for Microsoft Azure as well as Kubernetes.

This is the second post of a set of two blog posts in which we are covering the whole process to prepare, package, migrate, and deploy a .NET Core application to the cloud using Stacksmith.

The first part of this article, Migrating .NET Core Applications to the cloud with Stacksmith. Part 1: Preparing the application covers how to prepare the artifacts for the application. It is recommended that you go through the article to better understand the artifacts that are used by Stacksmith. In addition, I provide download links to prebuilt artifacts that can be used in the process of packaging a .NET Core application with Stacksmith.

Packaging and launching your .NET Core Application using Stacksmith

This section walks you through the process of migrating a sample .NET Core TO-DO application to the cloud. These are the steps you will follow in this post:

  1. Step 1 shows you how to get a working account on Stacksmith.
  2. Step 2 explains in detail how to interact with Stacksmith to package the application and get deployable artifacts.
  3. Step 3 offers a guide for launching those artifacts on both Azure and Kubernetes.

Step 1: Log in to Stacksmith

The first step is to log into stacksmith.bitnami.com with your Bitnami account. If you don't have an account with Bitnami, you'll be invited to create a new one. At the time of writing, a 30-day trial is available at stacksmith.bitnami.com.

The first time you sign into your Stacksmith account, you will need to onboard your cloud account credentials. This is necessary so that Stacksmith can securely package and store your applications and assets, as well as the images and artifacts it creates in your cloud account.

If you don't have a cloud account, here are instructions on how to obtain valid Azure credentials so you can use the service.

NOTE: In this post, I package the application for Azure, however, the packaging process is the same for AWS.

Step 2: Package your Application

Once you are logged in, you will be able to package your first app as shown below:

Package your application

To start the process, click the “Package your application” button. You will be prompted for some information and for several files before packaging your application.

In the resulting screen, fill in the form as follows:

  1. Give your application a name and a version number.
  2. Select the stack template - in this example, select the ".NET Core application with DB (MySQL)" stack template.
  3. Select the target platforms you would like to package the app for (you can select several).
  4. Upload the application code and the scripts that you have prepared in the first part of this article, Migrating .NET Core Applications to the cloud with Stacksmith. Part 1: Preparing the application

The files for this example can also be downloaded from the following links:

Create a new application

Click "Create" and wait for the build to complete. If you are impatient, you can see the logs of the build live!

Build logs

Once the process is finished, you will see that Stacksmith has created an ARM Template and a Helm chart.

The ARM Template describes the infrastructure that Microsoft Azure creates for serving your application and how to configure it.

In this case, it includes the Azure Database for MySQL as the database as well as a virtual machine that runs the .NET Core application. The template provides the .NET Core application with connectivity details to the Azure Database for the MySQL instance. It also sets up things like the required networking in order to make the internal communication possible as well as allow connectivity from the Internet.

The Helm Chart describes the equivalent set of resources for Kubernetes.

It contains all the manifest files that tell Kubernetes which pods, services, volumes, and other resources it should create, and how to connect them.

The containers that serve the .NET Core application are instantiated from the Docker image referenced by the image ID provided by Stacksmith.

Step 3: Launch The Application

So let’s launch the app. Instructions for running the application both in Azure and Kubernetes are provided below.

Deploy your application to Azure

Launch in Azure

  • On the view of your build for Azure cloud, click the “Launch in Azure” button.

You are redirected to the Microsoft Azure Portal where a dialog for launching the ARM Template is displayed:

Launching in Azure Portal

Most of these configuration settings are already filled in with default values that can be modified. There are some settings that must be specified in order to launch the application:

  • Choose your Azure Subscription if you are using multiple subscriptions.
  • Specify the name of the Resource group to be created; we recommend using lower case letters and digits only for this field.
  • Make sure that Location is East US.
  • Specify the Stack Name. This name is used as a prefix for all resources in Azure; we recommend using lower case letters and digits only for this field.
  • Specify your Virtual Machine Administrator Login. This is the name of the system user that you will be able to SSH in to the machine if needed.
  • Paste your SSH Public Key.This is then added as an authorized SSH key in order to access the machine.
  • Provide value for IP Range SSH. To make your machine globally accessible over SSH, you can specify (It may not be recommended for production, but is fine for testing purposes).
  • Provide value for IP Range Application. To make your machine globally accessible over HTTP, you can specify (It may not be recommended for production, but is fine for testing purposes).
  • Provide value for Database Password. Must be at least 8 characters long, consist of upper case letters, lower case letters and a digit, for example: AzureTest12345.
  • Check the I agree to the terms and conditions stated above check button.
  • Optionally, check the Pin to dashboard check button to make the deployment easier to find by adding it to your dashboard, which is the main screen for Azure Portal.
  • Click on Purchase to finish the process.

NOTE: While the button indicates Purchase, launching the ARM template will only create the cost of all of the resources that the template creates, such as the virtual machine running .NET Core application and a managed database.

This will start the launch of the ARM Template.

After the creation process finishes, in the deployment that was added to your dashboard, click on the "See more" option. Then, find the Public IP address in the list:

Click on the item and then copy the IP address from the details view. Next, to access the application, go to http://IP_ADDRESS:8080. Something similar to the following should be displayed:

.NET Core Application on Azure

Your application is now up and running in Azure.

Deploy your application to Kubernetes

NOTE: Before performing the following steps, make sure you have a Kubernetes cluster running, and that Helm and Tiller are installed correctly. For detailed instructions, refer to our Kubernetes starter tutorial. These steps also require your cluster to access the ACR registry that stores the images generated for you by Stacksmith. See Stacksmith documentation to configure ACR access.

  • On the view of your Kubernetes build, click on the "Download Helm chart" button. This downloads the custom Helm chart for your application as an archive.

Download Helm chart

  • Make sure you can connect to your Kubernetes cluster by executing the following command:
$ kubectl cluster-info
  • Use helm to install the chart:
$ helm install my-to-do-application-1-docker-719364341.tgz --name my-todo-app
  • This creates all the necessary resources in the cluster to run your application.
  • You can monitor the status of the deployment using the helm status command with the deployment name, as shown below:
$ helm status my-todo-app

Once the deployment is ready, you can see the application running as in the Azure example. Pay special attention to the NOTES section of the output.

Helm status output

Run the following commands and then go to to access the application:

$ export POD_NAME=$(kubectl get pods --namespace default -l "app=my-todo-app-net-core-sample-to-do-application" -o jsonpath="{.items[0].metadata.name}")
$ echo "Visit to use your application"
$ kubectl port-forward $POD_NAME 8080:8080

As you can see, Stacksmith provides a simple and convenient way to package and deploy your .NET Core application to Azure and Kubernetes.

Stacksmith supports other sets of runtimes. Check out the different templates that are available. It also supports multiple target platforms.

Package, deploy, and maintain your own .NET Core application today. Sign up for the Stacksmith 30 day free trial and find out how easy it is! And, if you have any feedback, let us know in our community forum. We look forward to hearing from you!