coreos/stern

Name: stern

Owner: CoreOS

Description: ? Multi pod and container log tailing for Kubernetes

Created: 2018-04-04 17:01:37.0

Updated: 2018-04-04 17:01:39.0

Pushed: 2018-04-04 22:25:55.0

Homepage:

Size: 121

Language: Go

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

stern

wercker status

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 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 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.

Installation

If you don't want to build from source go grab a binary release

Govendor is required to install vendored dependencies.

r -p $GOPATH/src/github.com/wercker
GOPATH/src/github.com/wercker
clone https://github.com/wercker/stern.git && cd stern
ndor sync
nstall
Homebrew

On macOS, you can also install Stern using Homebrew:

 install stern
Usage
n pod-query [flags]

The pod query is a regular expression so you could provide "web-\w" to tail web-backend and web-frontend pods but not web-123.

cli flags

| flag | default | purpose | |——————–|——————|————————————————————————————————————–| | --container | .* | Container name when multiple containers in pod (regular expression) | | --timestamps | | Print timestamps | | --since | | Return logs newer than a relative duration like 52, 2m, or 3h. Displays all if omitted | | --context | | Kubernetes context to use. Default to kubectl config current-context | | --exclude | | Log lines to exclude; specify multiple with additional --exclude; (regular expression) | | --namespace | | Kubernetes namespace to use. Default to namespace configured in Kubernetes context | | --kubeconfig | ~/.kube/config | Path to kubeconfig file to use | | --all-namespaces | | If present, tail across all namespaces. A specific namespace is ignored even if specified with –namespace. | | --selector | | Selector (label query) to filter on. If present, default to .* for the pod-query. | | --tail | -1 | The number of lines from the end of the logs to show. Defaults to -1, showing all logs. | | --color | auto | Force set color output. auto: colorize if tty attached, always: always colorize, never: never colorize |

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.

Examples:

Tail the gateway container running inside of the envvars pod on staging

n envvars --context staging --container gateway

Show auth activity from 15min ago with timestamps

n auth -t --since 15m

Follow the development of some-new-feature in minikube

n some-new-feature --context minikube

View pods from another namespace

n kubernetes-dashboard --namespace kube-system

Tail the pods filtered by run=nginx label selector across all namespaces

n --all-namespaces -l run=nginx

Follow the frontend pods in canary release

n frontend --selector release=canary
Completion

Stern supports command-line auto completion for bash or zsh. stern --completion=(bash|zsh) outputs the shell completion code which work by being evaluated in .bashrc, etc for the specified shell. In addition, Stern supports dynamic completion for --namespace and --context. In order to use that, kubectl must be installed on your environment.

If you use bash, stern bash completion code depends on the bash-completion. On the macOS, you can install it with homebrew as follows:

ew install bash-completion

Note that bash-completion must be sourced before sourcing the stern bash completion code in .bashrc.

ce <(brew --prefix)/etc/bash-completion
ce <(stern --completion=bash)

If you use zsh, just source the stern zsh completion code in .zshrc.

ce <(stern --completion=zsh)

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.