Fork of discontinued wercker/stern
Stern allows you to tail
multiple pods on Kubernetes and multiple containers
within the pod. Each result is color coded for quicker debugging.
The query is a regular expression or a Kubernetes resource in the form
<resource>/<name>
so the pod name can easily be filtered and
you don't need to specify the exact id (for instance omitting the deployment
id). If a pod is deleted it gets removed from tail and if a new pod is added it
automatically gets tailed.
When a pod contains multiple containers Stern can tail all of them too without
having to do this manually for each one. Simply specify the container
flag to
limit what containers to show. By default all containers are listened to.
Download a binary release
go install github.com/stern/stern@latest
If you use asdf, you can install like this:
asdf plugin add stern
asdf install stern latest
If you use Homebrew, you can install like this:
brew install stern
If you use Krew which is the package manager for kubectl plugins, you can install like this:
kubectl krew install stern
stern pod-query [flags]
The pod-query
is a regular expression or a Kubernetes resource in the form <resource>/<name>
.
The query is a regular expression when it is not a Kubernetes resource,
so you could provide "web-\w"
to tail web-backend
and web-frontend
pods but not web-123
.
When the query is in the form <resource>/<name>
(exact match), you can select all pods belonging
to the specified Kubernetes resource, such as deployment/nginx
.
Supported Kubernetes resources are pod
, replicationcontroller
, service
, daemonset
, deployment
,
replicaset
, statefulset
and job
.
flag | default | purpose |
---|---|---|
--all-namespaces , -A |
false |
If present, tail across all namespaces. A specific namespace is ignored even if specified with --namespace. |
--color |
auto |
Force set color output. 'auto': colorize if tty attached, 'always': always colorize, 'never': never colorize. |
--completion |
Output stern command-line completion code for the specified shell. Can be 'bash', 'zsh' or 'fish'. | |
--condition |
The condition to filter on: [condition-name[=condition-value]. The default condition-value is true. Match is case-insensitive. Currently only supported with --tail=0 or --no-follow. | |
--config |
~/.config/stern/config.yaml |
Path to the stern config file |
--container , -c |
.* |
Container name when multiple containers in pod. (regular expression) |
--container-colors |
Specifies the colors used to highlight container names. Use the same format as --pod-colors. Defaults to the values of --pod-colors if omitted, and must match its length. | |
--container-state |
all |
Tail containers with state in running, waiting, terminated, or all. 'all' matches all container states. To specify multiple states, repeat this or set comma-separated value. |
--context |
The name of the kubeconfig context to use | |
--diff-container , -d |
false |
Display different colors for different containers. |
--ephemeral-containers |
true |
Include or exclude ephemeral containers. |
--exclude , -e |
[] |
Log lines to exclude. (regular expression) |
--exclude-container , -E |
[] |
Container name to exclude when multiple containers in pod. (regular expression) |
--exclude-pod |
[] |
Pod name to exclude. (regular expression) |
--field-selector |
Selector (field query) to filter on. If present, default to ".*" for the pod-query. | |
--highlight , -H |
[] |
Log lines to highlight. (regular expression) |
--include , -i |
[] |
Log lines to include. (regular expression) |
--init-containers |
true |
Include or exclude init containers. |
--kubeconfig |
Path to the kubeconfig file to use for CLI requests. | |
--max-log-requests |
-1 |
Maximum number of concurrent logs to request. Defaults to 50, but 5 when specifying --no-follow |
--namespace , -n |
Kubernetes namespace to use. Default to namespace configured in kubernetes context. To specify multiple namespaces, repeat this or set comma-separated value. | |
--no-follow |
false |
Exit when all logs have been shown. |
--node |
Node name to filter on. | |
--only-log-lines |
false |
Print only log lines |
--output , -o |
default |
Specify predefined template. Currently support: [default, raw, json, extjson, ppextjson] |
--pod-colors |
Specifies the colors used to highlight pod names. Provide colors as a comma-separated list using SGR (Select Graphic Rendition) sequences, e.g., "91,92,93,94,95,96". | |
--prompt , -p |
false |
Toggle interactive prompt for selecting 'app.kubernetes.io/instance' label values. |
--selector , -l |
Selector (label query) to filter on. If present, default to ".*" for the pod-query. | |
--show-hidden-options |
false |
Print a list of hidden options. |
--since , -s |
48h0m0s |
Return logs newer than a relative duration like 5s, 2m, or 3h. |
--stdin |
false |
Parse logs from stdin. All Kubernetes related flags are ignored when it is set. |
--tail |
-1 |
The number of lines from the end of the logs to show. Defaults to -1, showing all logs. |
--template |
Template to use for log lines, leave empty to use --output flag. | |
--template-file , -T |
Path to template to use for log lines, leave empty to use --output flag. It overrides --template option. | |
--timestamps , -t |
Print timestamps with the specified format. One of 'default' or 'short' in the form '--timestamps=format' ('=' cannot be omitted). If specified but without value, 'default' is used. | |
--timezone |
Local |
Set timestamps to specific timezone. |
--verbosity |
0 |
Number of the log level verbosity |
--version , -v |
false |
Print the version and exit. |
See stern --help
for details
Stern will use the $KUBECONFIG
environment variable if set. If both the
environment variable and --kubeconfig
flag are passed the cli flag will be
used.