Junior — Middle
How can you get and view container execution logs in Kubernetes?
sobes.tech AI
Answer from AI
To obtain and view container logs in Kubernetes, the kubectl logs command is used.
Example usage:
kubectl logs <pod-name>
If the Pod has multiple containers, you need to specify the container name:
kubectl logs <pod-name> -c <container-name>
To view logs with follow (like tail -f):
kubectl logs -f <pod-name>
You can also retrieve logs from a previous instance of a container if it has been restarted:
kubectl logs --previous <pod-name>
Thus, kubectl logs allows quick access to the stdout and stderr of containers, aiding in debugging and monitoring applications.