Deploying DotNet Core Application using Kubernetes

In my last blog, I talked about hosting a sample application using docker. Now, continuing with the series like we mentioned, we’ll talk about how to deploy DotNet Core application using Kubernetes.

First things, first, since you are here to learn how to deploy a DotNet application, we believe that you already have a sample dotnet core application ready with you. Secondly, the deployment steps mentioned here have been performed on a Ubuntu16.04 machine.

Step 1: Creating dockerfile

  • Create a dockerfile with the following contents and place it in the root location of the project repository.

Note: Don’t forget to replace the project_name with the actual project name.

  • Create startup.sh file with the following contents and place it in the root location of the project repository.

Note: Don’t forget to replace the project_name with the actual project name.

Step 2: Creating Kubernetes yaml file

  • Create a Kubernetes yaml file (dotnetapi.yaml) with the following contents and place it in the root location of the project repository.

The above snippet comprises of:

  • apiVersion — which version of the Kubernetes API is being used to create this object
  • kind — what kind of object is being created
  • metadata — data that helps uniquely identify the object, including a name string, UID, and optional namespace
  • spec — what state is being desired for the object

The selector field defines how the deployment find the pods to manage, it is defined in the template (app: sample-dotnet). The template.spec defines the docker image being used to create the pod. Replace the ip_address_of_the_machine:5000 with the private docker registry details. The containerport defines the port on which application will run inside the pod.

The Kubernetes Service section: The Kubernetes services is responsible for enabling network access to a set of pods.

  • port: defines the port on which application is running inside the pod
  • nodePort: defines the port to be bind to the base machine
  • protocol: TCP default protocol for the network communication
  • selector: to identify the deployment created above

Step 3: Jenkins Configuration

  • Creating Jenkins job
  • Open the Jenkins url and click on “New Item”
  • Provide a name for the job and select freestyle job
  • Provide the git repository url and credentials for cloning the project. Also specify the branch
  • Select “Execute Shell” from the add build step
  • Provide the steps as shown
  • Save the job and execute it
  • This will create docker image and push to the private docker registry. Also, the kubectl apply command will configure the pod with dotnet core application running inside it. The purpose of pushing the docker image to the docker registry is that this image can be used on any other Ubuntu machine to run the application.
  • Access the sample application on the url http://ip_address_of_machine:30295

And voila we are done! The next in line in the automated deployment series is how to ‘Deploy NodeJs applications using Kubernetes.’

Akeo

Official Medium publication for Akeo.Tech

Akeo

Official Medium publication for Akeo.Tech focusing on innovation and spreading awareness about technologies that can disrupt current business models. Follow us to get deep insights into blockchain, AI & ML, Fintech, and Industry 4.0. More info at — www.akeo.tech

Simarpreet Singh Gujral

Written by

Akeo

Official Medium publication for Akeo.Tech focusing on innovation and spreading awareness about technologies that can disrupt current business models. Follow us to get deep insights into blockchain, AI & ML, Fintech, and Industry 4.0. More info at — www.akeo.tech