3 Topics I am Exploring In My Life Right Now

The topics occupying my mind right now are e-commerce, cookieless advertising, and mobile app marketing. Targeting iOS users is a challenge right now and retargeting ads have taken a hit. Are…

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




Running a .NET application on a local Kubernetes cluster

Docker and containers are a relative new tool, being more and more used on the software development. This tool helps you to create easily configurable enviroments for your applications, you don`t need anymore to have several SDKs and databases installed on your machine.

But, sometimes when your application grows and have several containers running, you may need to orchestrate and manage the behave of the whole application. And here comes Kubernetes to do this job for you.

Kubernetes is a docker container orchestrator, which helps you define the behavior of your containers, like doing autoscalling, loag balance, memory control and create a private network for your application. This tool is traditionally used on the cloud applications (because you don`t have hardware limitations, making possible horizontal scalability in seconds), but you can run on your machine too!

The tool that makes this possible is Kind (a.ka. Kubernetes in Docker), that emulates a kubernetes cluster on a docker container. This tool basically is going to put all your application`s containers inside the kubernetes docker container created by kind.

To run this application, you only need these tools installed on your machine:

These tools are avaliable on all operating systems (Windows, Linux and Mac OS), you can easily install them on the command-line by package control tools (homebrew, chocolately apt-get and others).

Application

The application that we are going to run is irrelevant, is just a REST API with one GET endpoint that return a Guid. The focus is on containerize and run it on a cluster.

You can download the application on my Github account, the repo is public:

The project is very simple, you have the src folder where the .NET application is stored and the kubernetes folder where we are going to store the kubernetes policies (the scripts that we define the behave of the cluster).

In this application, we are only talk about two relevant files that our cluster depends on them:

The Dockerfile is the file where we are going to build the image of our application, in this case our .NET REST API. Here how the file looks like:

And on the manifest file, is the policy used by kubernetes, where we setup, configure and provision the cluster behaviour. The file looks like it:

When everything is installed, we can start to setup our enviroment.

The firs step is to download the project on your machine, and on the terminal stay on the root folder of the project, like on the picture below:

Now we need to containerize our .NET REST API, creating a docker image to be runned on the cluster.

This command might take a while, after it finishes, you can verify if the image was created sucessfully, with the command:

Now we are going to start the cluster:

This command might take a while too, but after it finishes, it must had created another docker image.

If both images were created, we need to put our application image (guid-api) inside the cluster image (kindest/node).

And apply our policy on this cluster.

After you apply this manifest file, if you modify the file, just run again the command, and the cluster policy is going to be updated.

After these commands, we need to wait for the cluster to be ready, we can verify this with the following commands:

f both shows readyyour application is ready to go. If not, and spent a significant time, may something is broken (must probably on the kubernetes manifest).

To see the log of the .NET application, type:

You cannot access the application yet, because is pointing to a port on localhost inside the cluster. You must point to a port on the localhost of your machine:

The guid-api-5458fcbfd5-qmks8 is the name of the pod of our application, showed on the get pods command before.

We did it! Now our application is running on a cluster. On the nexts articles I am going to show how we can put more applications on our cluster (a frontend and backend) and how you can run this same application on a cloud provider.

Add a comment

Related posts:

Seven Things I am Thankful For

The next seven days will be spent sharing a list of things I am thankful for. It’s a decision to be grateful for the seemingly little things which we sometimes miss. Truth is, we really cannot do…

Elusive

We sat on our familiar seats in total silence each avenue explored had closed in and in the dropping of a pin we jumped startled to realize that our chance had flown by Elusive lines and too many…

Advancing Time in Truffle Solidity Tests

Advancing Time in Truffle Solidity Tests. In this article I’ll go over one way to advance the block time of your contracts in Truffle-Solidity tests..