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.
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.
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.
- 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.