Stern is a powerful utility designed to streamline the process of tailing logs from Kubernetes clusters. It allows developers to specify both pod and container IDs using regular expressions, offering a flexible and efficient way to monitor application behavior. This tool is invaluable for debugging and operational insights within complex Kubernetes environments.
Installing Stern on macOS is straightforward using Homebrew:
brew install stern
Here are some common examples to get you started with Stern:
To tail logs from pods whose names start with my-pods- in the default namespace:
stern -n default my-pods
To tail logs from the same pods but only for the web container:
stern -n default my-pods --container web
To view logs from the web container in the specified pods, starting from 1 minute ago:
stern -n default my-pods --container web --since 1m