Fail to run a .NET app in Kubernetes in Kind

Viewed 171

I'm trying to deploy a simple .NET App in local kubernetes cluster (Kind) for testing purposes. When a deployment is applied, a pod doesn't start with an error. But the image is built well as a container works well if started locally in Docker.

NAME                             READY   STATUS    RESTARTS   AGE
orderproducer-68d5ff7944-d2d89   0/1     Error     4          103s
kubectl logs -l app=orderproducer

Could not execute because the application was not found or a compatible .NET SDK is not installed.
Possible reasons for this include:
  * You intended to execute a .NET program:
      The application 'OrderProducer.dll' does not exist.
  * You intended to execute a .NET SDK command:
      It was not possible to find any installed .NET SDKs.
      Install a .NET SDK from:
        https://aka.ms/dotnet-download

It's weird, because if I start a docker container from the same image locally (not in a cluster) it works well. Besides, I had run bash on that container and ensured that OrderProducer.dll was really presented in the /app folder (which is a workdir).

xxx@xxx:/mnt/c/Users/xxx$ docker run --name test6 orderproducer:latest
Order Producer has started!
Kafka broker: 127.0.0.1:9092

Do you have any ideas what's my mistake? Why it run in Docker, but not in a K8s's pod? I've already spent about 3 hours trying to figure out, but still not. Many thanks in advance.

Here are some artifacts I used.

Dockerfile:

FROM mcr.microsoft.com/dotnet/runtime:6.0 AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["OrderProducer/OrderProducer.csproj", "OrderProducer/"]
COPY ["Common/Common.csproj", "Common/"]
RUN dotnet restore "OrderProducer/OrderProducer.csproj"
COPY . .
WORKDIR "/src/OrderProducer"
RUN dotnet build "OrderProducer.csproj" -c Release -o /app/build

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

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "OrderProducer.dll"]

Then I build an image and make it accessible for kind:

docker build -f OrderProducer/Dockerfile -t orderproducer:latest .
kind load docker-image orderproducer:latest

Then I apply a deployment:

kubectl apply -f orderproducer-deployment.yml

orderproducer-deployment.yml

apiVersion: apps/v1
kind: Deployment
metadata:
  name: orderproducer
spec:
  replicas: 1
  selector:
    matchLabels:
      app: orderproducer
  template:
    metadata:
      labels:
        app: orderproducer
    spec:
      containers:
      - name: orderproducer
        image: orderproducer:latest
        imagePullPolicy: Never
        resources:
          limits:
            memory: "128Mi"
            cpu: "500m"
1 Answers

The reason was when a volume was mounted to /app it wiped out all the container's /app content.

I fixed the issue by editing the following deployment's part:

volumeMounts:
        - name: appsettings-volume
          mountPath: /app/appSettings.json
          subPath: appSettings.json
Related