Unable to run .netcore app as kubernetes cronjob

I would like to create a kubernetes CronJob scheduler which can invoke .netcore console application every minute.

kindest/node:v1.18.2

CronJob Spec [cronjob-poc.yml]:

    kind: CronJob

    metadata:

      name: cronjob-poc

    spec:

      schedule: "*/1 * * * *" #Every Minute

      jobTemplate:

        spec:

          template:

            spec:

              containers:

              - name: cronjob-poc

                image: cronjobpoc:dev

                command: ["/usr/local/bin/dotnet", "/app/CronJobPoc.dll"]

              restartPolicy: OnFailure

Kind Commands:

kind create cluster --name=cronjob-poc

kind load docker-image cronjobpoc:dev --name=cronjob-poc

kubectl apply -f .\cronjob-poc.yml

.netcore is a very simple app which just prints hello

using System;

namespace CronJobPoc{

    class Program{

        static void Main(string[] args)
        {
            Console.WriteLine($"{DateTime.Now} - Hello World!");
        }
    }
}

Docker File:

FROM mcr.microsoft.com/dotnet/core/runtime:3.1-buster-slim AS base    
WORKDIR /app    
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build    
WORKDIR /src    
COPY ["CronJobPoc/CronJobPoc.csproj", "CronJobPoc/"]    
RUN dotnet restore "CronJobPoc/CronJobPoc.csproj"    
COPY . .    
WORKDIR "/src/CronJobPoc"    
RUN dotnet build "CronJobPoc.csproj" -c Release -o /app/build    
FROM build AS publish    
RUN dotnet publish "CronJobPoc.csproj" -c Release -o /app/publish    
FROM base AS final    
WORKDIR /app    
COPY --from=publish /app/publish .    
ENTRYPOINT ["dotnet", "CronJobPoc.dll"]

When I do kubectl get pods I see below information.

NAME                           READY   STATUS             RESTARTS   AGE

cronjob-poc-1589463060-9dp8p   0/1     CrashLoopBackOff   4          2m51s

When I try to see logs using kubectl logs cronjob-poc-1589463060-9dp8p I do not see anything. The command returns empty.

Not sure how to see the logs. There is something wrong but not sure what?

I am expecting to see the output " - Hello World!" somewhere in the log. Not sure how to check what went wrong and where can the logs with proper error messages can be seen.

Any quick help on this would be highly appreciated.

I also tried using command argument as shown below in cronjob-poc.yml. I get CrashLoopBackOff status for the pod

command:
- /bin/sh
- -c
- echo Invoking CronJobPoc.dll ...; /usr/local/bin/dotnet CronJobPoc.dll

When I try to check the log using kubectl logs , I see /bin/sh: 1: /usr/local/bin/dotnet: not found

I tried below option:

        command:
        - /bin/sh
        - -c
        - echo dotnet - $(which dotnet);
          echo Executing dll ...;
          /usr/bin/dotnet /app/CronJobPoc.dll

It gave me error,

dotnet - /usr/bin/dotnet
Executing dll …
It was not possible to find any installed .NET Core SDKs
Did you mean to run .NET Core SDK commands? Install a .NET Core SDK from:
https://aka.ms/dotnet-download

You can format your yaml by highlighting it and pressing Ctrl-Shift-C, it will make your output easier to read.

I pulled down the image, the location for the dotnet binary is /usr/bin/dotnet instead of /usr/local/bin/dotnet

Thanks for your reply @mrbobbytables
Will try your suggestion. When I echo which dotnet I see ‘/usr/bin/dotnet’

@mrbobbytables
I did try /usr/bin/dotnet I am seeing below messages in kubectl logs…

It was not possible to find any installed .NET Core SDKs
Did you mean to run .NET Core SDK commands? Install a .NET Core SDK from:

I can’t be of much help there without diving into it more =/ but the issue is with your container image / command you’re running. I’d work on fixing that solely in docker before attempting to run it on kubernetes.

@mrbobbytables This is a simple .netcore application which prints just ‘Hello World’.
Yes. I did try to first run in docker and it runs successfully and prints ‘Hello World’ message.
Then I tried to run it as Kubernetes cronjob. My goal here is to see ‘Hello World’ message.