29
- October
2019
Posted By : Alexander Goida
Deploying your .NET Core app to Kubernetes on local Windows machine

Concise guide with commands about deploying .NET Core application to local .

First of all, make sure you’ve installed as described here.

Dockerfile

The base image for the container depends on your choice about OS where it is Linux or Windows. You can find a correct one here. Below is the example which I’m using for .NET Core v2.2 witn Linux-based containers. All source code is located under src folder in my project.

Deploying

There are several ways to deploy the application locally: on local , using -compose and on local Kubernetes.

If you’re using image you need to refresh the local copy using pull command. The option -d will start containers detached. The command stop will remove deployment.

Docker

At first, build an image of your application.

The option --progress plain will output all logs during the building to the console. You can use the image after this operation complete.

The command images will show all images in your local registry. With run you can start new container with your image. The command ps will show you running containers. You will need to manually stop container to release resources using CONTAINER ID from the output of ps command.

Kubernetes (k8s)

Here I’ll deploy manually the app by creating a deployment and service on k8s. After that I’ll extract YAML specification of the current deployment to simplify deployment in the future. You need to have local Docker image before going with next steps. Now let’s create a deployment using the image.

The option --image-pull-policy set the kubelet to pull image when pods are started. Now create a service (read more about it here):

The option --port specify external port. You can use the following command to get information about resources in k8s and delete the service (pod will be automatically terminated by k8s).

When we have running pods, service and deployment in k8s, let’s extract YAML specification for this to create all them at once in the future. Below I show commands for extracting configuration to file and applying the file to k8s.

In the file you can specify parameters of the service, number of pods, etc.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.