kubernetes: no log retrieved by kubectl

大兔子大兔子 提交于 2021-02-05 06:14:23

问题


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?


回答1:


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.




回答2:


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).



来源:https://stackoverflow.com/questions/52556187/kubernetes-no-log-retrieved-by-kubectl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!