kubernetes: no log retrieved by kubectl

9/28/2018

I am trying to run a simple image on a specific namespace to debug some issues

kubectl run busy --image busybox --namespace my-local-dev 
deployment.apps/busy created

However for some reason the container keeps restarting

busy-67b577b945-ng2lt                     0/1       CrashLoopBackOff   5          3m

and I am unable to get any logs, even with the --previous flag

$ kubectl logs -f --namespace my-local-dev busy-67b577b945-ng2lt --previous
Unable to retrieve container logs for docker://c8b9fce066686b3be01df1ed3343be5ec65607cb203e054fd9365511f77bd4af/home/pkara/Desktop
$ kubectl logs -f --namespace my-local-dev busy-67b577b945-ng2lt
$ _

Any suggestions?

-- pkaramol
kubectl
kubernetes
logging

2 Answers

9/28/2018

K8S behind the scenes starts a Container. Containers requires command(s) to keep running in the foreground. Otherwise, it thinks that application is stopped and it shutdown the container. More here.

Also, no generator is specified and so a Deployment, ReplicationSet and a Pod are created by default. And the ReplicationSet is starting the container after the crash.

Run the below command and it will give a shell prompt to debug any issues. It won't also crash.

kubectl run busy --image busybox --namespace my-local-dev -it --generator=run-pod/v1

For the sake of debugging there is no need for a robust system including a Deployment and ReplicationSet. Using the above generator will make sure only a Pod is run and not other resources (Deployment and ReplicationSet).

-- Praveen Sripati
Source: StackOverflow

9/28/2018

CrashLoopBackOff means that your pod continues on crashing and gets restarted and crashes again.

Depending on the point of crash, for example soon at startup or later during the execution of your app, you may or may not see the logs.

In this case (no logs shown) it's likely that your pod has NOT some requested resources available. It may be a secret or a volume, for example.

A good way is to watch Kubernetes events: kubectl get events

Or in similar way describe your resource and read the relative events: kubectl describe pod <pod_name>, the last part of the screen is dedicated to events on that resource.

-- Nicola Ben
Source: StackOverflow