kubectl logs returns nothing (blank) kubectl logs returns nothing (blank) kubernetes kubernetes

kubectl logs returns nothing (blank)


I am using a multi-stage docker build, and was building using the wrong target! (I had cloned a previous Visual Studio docker build task, which had the following argument:

--target=test

Because the "test" build stage has no defined entry point, the container was launching and then exiting without logging anything! So that's why kubectl logs returned blank.

I changed this to

--target=final

and all is working!

My Dockerfile looks like this:

FROM microsoft/dotnet:2.1-aspnetcore-runtime AS baseWORKDIR /appEXPOSE 80FROM microsoft/dotnet:2.1-sdk AS buildWORKDIR /srcCOPY . .WORKDIR "/src"RUN dotnet clean ./ST.Web/ST.Web.csprojRUN dotnet build ./ST.Web/ST.Web.csproj -c Release -o /appFROM build AS testRUN dotnet tool install -g dotnet-reportgenerator-globaltoolRUN chmod 755 ./run-tests.sh && ./run-tests.shFROM build AS publishRUN dotnet publish ./ST.Web/ST.Web.csproj -c Release -o /appFROM base AS finalWORKDIR /appCOPY --from=publish /app .ENTRYPOINT ["dotnet", "ST.Web.dll"]


that happens because pod is already destroyed, try doing:

kubectl logs web-deployment-76789f7f64-s2b4r --previous

this will show logs from the previous pod.