How to deploy a service to Kubernetes on Docker through Helm

quoctuan.cqt@gmail.com | 254 day | 314


In this article, I will show you how to deploy a service to Kubernetes on Docker through Helm and Visual Studio 2019. This is the simplest and easy way which is different from Butter's Article.

Prerequisite:

Setup Kubernetes

First, you need to install Docker on your machine and enable Kubernetes. 

Note: You must switch to Linux Container to see the Kubernetes tab in Settings.

Next, you need to grant permission for docker service on Shared Drives tab.

Uses this command to verify Kubernetes work or not by using Command Prompt.

kubectl version

Congratulations! Kubernetes is running on your machine.

Config your application/services

  • Open/Create your application/services using Visual Studio 2019. In this article, I use the new project with Donet Core API template.
  • Right-click on the startup project and select Add > Container Orchestrator Support...

  • It will show you a popup to select the type of container orchestrator

  •  Select Kubernetes/Helm. If you don't see this option, please make sure you installed Azure Development in Visual Studio

  •  Visual Studio will generate some folder/files for deployment.
    • charts: This is all required files need to config for Helm (the same like what will generate with "helm create" command)
    • azds.yaml: This file uses to config for azure deployment (you can ignore this file in this tutorial, it's simple and useful when you need to deploy on Azure Kubernetes Service)
    • Dockerfile: This file uses to build Docker image 
  • You need to modify a little bit in Dockerfile
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS base
WORKDIR /app
EXPOSE 80

FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build
WORKDIR /src
COPY ["WebApplication1.csproj", "WebApplication1/"] #Removed the folder

RUN dotnet restore "WebApplication1/WebApplication1.csproj"
COPY . ./WebApplication1 #Copy all file into folder
WORKDIR "/src/WebApplication1"
RUN dotnet build "WebApplication1.csproj" -c Release -o /app

FROM build AS publish
RUN dotnet publish "WebApplication1.csproj" -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "WebApplication1.dll"]
  • Build your Docker image using this command
docker build -t demo:stable .
  • Verify your image is created successfully.
docker images

  • Navigate to charts folder and uses this command to deploy to Kubernetes.
helm install --name webapplication1 .

  • Check your pod is running as well
kubectl get pods

  • Finally, you need to run the command that mentioned in the result of "helm install" statement to map the port to your container
kubectl port-forward [YOUR POD NAME] 8080:80

  • Verify the application/services

Looks great! Hope this article helps you to get started with Docker and Kubernetes. If you have any question, please leave me a comment, I will reply as soon as possible.

Next article, I will show you how to connect service on Kubernetes with your local SQL server.

 

 

Top Articles

Bất Đầu Với WebApi Và Dot Net Core (.Net Core)

1131 day
Butter Ngo
Views 6824
Comments 0

Repository Và Unit Of Work (Entity Framework)

1050 day
ndtung449@gmail.com
Views 4162
Comments 0

Dot Net Core Bearer Token With (JWT) (.Net Core)

1063 day
Butter Ngo
Views 4159
Comments 0

Bắt Đầu Với Dot NET Core (.Net Core)

1143 day
Butter Ngo
Views 3834
Comments 0

Top Question

Bi lỗi Invalid Column Name khi sử dụng LinQ (.Net)

990 day
Bảo Dương
Views 1058
Answers 2

Làm thế nào để lấy information từ token (.Net Core)

380 day
ngovu.dl@gmail.com
Views 604
Answers 1

.NET CORE API JWT (.Net Core)

283 day
huynhminhnhut97@gmail.com
Views 595
Answers 2