If you’ve spent any amount of time in the Kubernetes world, then you know that it’s a complex system to master. Luckily for us, we don’t need to understand all of its inner workings. All we really need is kubectl and maybe a couple of commands about pods and services. In this post, I’ll show you how to view pod logs with kubectl.
You can find the logs of any Kubernetes pod by running kubectl logs. This command will show you all logs in real-time, which is very useful for debugging. You can specify the name or ID of the pod to limit what you see.
The first step in this process is to get the name of the pod using the following command.
kubectl get pods
Once I have the pods name, I will use the logs commands. In the example below, I am using the –tail=5, which means I will only get the last five lines of logs. To view more, change the number and see all the logs entry remove the –tail=5.
kubectl logs nginx-deployment-86d969f476-sjbr2 --tail=5
Leave a Reply