'Deploy .NET 6 WebAPI to local Kubernetes cluster using Skaffold
I created a most basic WebAPI project in .NET 6 (basically the weatherforecast api sample), and can run in just fine in Visual Studio with Docker. I'd like to use Skaffold to develop and continuously update local deployments to a minikube cluster in my local Kubernetes.
The solution in Visual Studio so you can see where all my files sit: VS Solution Explorer
The Dockerfile:
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["SkaffoldAPIDemo/SkaffoldAPIDemo.csproj", "SkaffoldAPIDemo/"]
RUN dotnet restore "SkaffoldAPIDemo/SkaffoldAPIDemo.csproj"
COPY . .
WORKDIR "/src/SkaffoldAPIDemo"
RUN dotnet build "SkaffoldAPIDemo.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "SkaffoldAPIDemo.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "SkaffoldAPIDemo.dll"]
My deployment manifest:
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app: skaffold-api-demo
name: skaffold-api-demo
spec:
replicas: 1
selector:
matchLabels:
app: skaffold-api-demo
template:
metadata:
labels:
app: skaffold-api-demo
spec:
containers:
- image: skaffold-api-demo
name: skaffold-api-demo
ports:
- containerPort: 8080
name: http
---
apiVersion: v1
kind: Service
metadata:
name: skaffold-api-demo
spec:
selector:
app: skaffold-api-demo
ports:
- port: 8080
name: http
And lastly, my skaffold.yaml file:
apiVersion: skaffold/v2beta28
kind: Config
metadata:
name: skaffoldapidemo
build:
artifacts:
- image: skaffold-api-demo
context: SkaffoldAPIDemo
docker:
dockerfile: Dockerfile
deploy:
kubectl:
manifests:
- SkaffoldAPIDemo/deploy/skaffoldapidemo.yaml
portForward:
- resourceType: service
resourceName: skaffoldapidemo
port: 8080
I am fairly new to containerisation and K8s, as well as obviously Skaffold, so likely I am making a very newbie mistake, but I can't see to get through it. When I run skaffold run from the powershell, I get the following error message:
It apparently cannot find the csproj file, but as far as I can tell, since I'm calling the command from the root folder of the solution, and my Docker file and skaffold.yaml file use the complete folder path to that csproj file, it should work just fine?
Somebody with more experience on deploying locally using skaffold in .NET probably can solve this quite fast, but to be honest, the amount of guides on this are very very limited.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
