How to deploy a service to Kubernetes on Docker through Helm | 399 day | 469

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.


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 AS base

FROM AS build
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
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)

1276 day
Butter Ngo
Views 8931
Comments 0

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

1208 day
Butter Ngo
Views 5557
Comments 0

Repository Và Unit Of Work (Entity Framework)

1195 day
Views 5039
Comments 0

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

1287 day
Butter Ngo
Views 4424
Comments 0

Top Question

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

1135 day
Bảo Dương
Views 1338
Answers 2


428 day
Views 939
Answers 2

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

525 day
Views 851
Answers 1