When deploying workloads, you may encounter warnings or errors. Kubernetes pods are no exception. Problems can be more easily solved by taking a look at the logs. But how do you find the latest logs of a particular pod?
The standard command for this is:
kubectl get events
We can sort the output by timestamp and filter on a specific pod.
kubectl get events --sort-by=.metadata.creationTimestamp -n <podname>
kubectl get events --sort-by=.metadata.creationTimestamp -n <podname> | nl
Live display of events
In the Linux world, there is the tail command to display the most recent entries of a log file. In Kubernetes the analogous command is:
kubectl logs --follow <podname>