How to view logs in Kubernetes?

There are various methods for viewing Pod logs in Kubernetes.

  1. View the logs of a Pod using the kubectl command.
kubectl logs <pod-name>

You can use the command above to view the logs of a specified Pod, and you can also use the following command to view the logs of a specific container.

kubectl logs <pod-name> -c <container-name>
  1. Track the logs of a Pod in real time using the kubectl command.
kubectl logs -f <pod-name>

The above command enables real-time tracking of the specified Pod’s log output.

  1. Use the `kubectl exec` command to access the inside of a Pod and view the logs.
kubectl exec -it <pod-name> -- sh

You can access the specified Pod’s container with the above command, then use commands like cat and tail to view the logs within the container.

In addition to the above methods, you can also use tools like Dashboard, Elasticsearch, and Fluentd to view logs of Pods in the Kubernetes cluster.

bannerAds