Run console application in google cloud>kubernetes

3/18/2021

My Code:

 public static void Start()
    {
       
        tcpListener = new TcpListener(IPAddress.Any, 26950);
        tcpListener.Start();
        tcpListener.BeginAcceptTcpClient(TCPConnectCallback, null);
        while(true){Thread.Sleep(500);}
       
    }
    private static void TCPConnectCallback(IAsyncResult _result)
    {

        TcpClient _client = tcpListener.EndAcceptTcpClient(_result);
         //Assign _client to local server
    }

My Dockerfile to create and upload an Image:

FROM mcr.microsoft.com/dotnet/sdk

COPY . /app

WORKDIR /app

RUN dotnet publish -c Release -o out

ENTRYPOINT ["dotnet", "Test.dll"]

Command in Cloud Shell:

gcloud builds submit --tag gcr.io/t****/i****

After this, I deploy it on Kubernetes Engine>Workloads

Error: CrashLoopBackOff

Solution:

FROM mcr.microsoft.com/dotnet/sdk:3.1
WORKDIR /app

COPY . .

ENTRYPOINT ["dotnet", "run"]
-- user13563819
c#
google-cloud-platform
google-kubernetes-engine
kubernetes
server

1 Answer

3/23/2021

The error CrashLoopBackOff indicates that a container is repeatedly crashing after restarting. A container might crash for many reasons

For example:

You can get more info about your error the CrashLoopBackOff error to know why your Pod's container is crashing

To see all Pods running in your cluster, run the following command:

kubectl get pods

And to get the Pod's logs, run the following command:

kubectl logs [POD_NAME]

You can also pass in the -p flag to get the logs for the previous instance of a Pod's container, if it exists.

Check "Exit Code" of the crashed container

You can find the exit code by performing the following tasks:

  1. Run the following command:
kubectl describe pod [POD_NAME]
  1. Review the value in the containers: CONTAINER_NAME: last state: exit code

Additionally, check if it has restarts.

For example you can use the command

watch -n1 kubectl get pods POD_NAME

To see if the pod got some of the following states:

creatingContainer -->  running --> completed --> crashloopbackoff

You could see more information about it in the following link

Also you can check this article that can help you with this issue What is a CrashLoopBackOff? How to alert, debug / troubleshoot, and fix Kubernetes CrashLoopBackOff events.

Finally, if you provide more information like the logs and more details, the community could help you more.

Edit 1

Looks like your problem come from the FROM mcr.microsoft.com/dotnet/sdk

I have found the following documentation: Create a Dockerfile for an ASP.NET Core application You could try to use something like:

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env

According to the official documentation : microsoft-dotnet-sdk these are the feature tags:

  • 5.0 (Current)
docker pull mcr.microsoft.com/dotnet/sdk:5.0
  • 3.1 (LTS)
docker pull mcr.microsoft.com/dotnet/sdk:3.1
-- Jose Luis Delgadillo
Source: StackOverflow