kt is short for Kubernetes Tail. It behaves like kubectl logs -f and
its usage is similar to kubectl get.
- Tail all containers in a pod by default.
- Automatically tail new pods, discard deleted pods and retry if the pod switches to running phase from pending phase.
- Recover from containers restart.
- Filter logs by query DSL with
and,or, parentheses, and quoted strings. - Auto-hide pod/container prefix when tailing a single container.
- Auto completion.
- Colorized output.
NOTE: If you install
ktusing homebrew, the completion is already installed.
Load the completion code into current shell
## bash
$ source <(kt --completion bash)
## zsh
$ source <(kt --completion zsh)
$ kt foo
or
$ kt 'foo-\w+'
$ kt -n prod -lapp=foo
Currently only the following resources are supported:
- Service
- Deployment
- StatefulSet
- DaemonSet
- HPA
- Job
- ReplicaSet
- ReplicationController
- CronJob
$ kt hpa foo
# You could limit which containers are tailed using regexp
$ kt -c 'sidecar-\w' svc foo
$ kt -n test --tail 30 deploy foo
$ kt --timestamps sts foo
$ kt --context prod ds foo
$ kt --cluster dev job foo
Use -q/--query to filter log lines with a boolean DSL:
# Match lines containing both keywords
$ kt deploy foo -q 'error and timeout'
# Match lines containing either keyword
$ kt deploy foo -q 'error or warning'
# Use parentheses to group expressions (and binds tighter than or)
$ kt deploy foo -q '(error or warn) and timeout'
# Use quotes for keywords with spaces
$ kt deploy foo -q '"error code" and 500'
The --prefix flag controls pod/container prefix display:
auto(default): hide prefix when tailing a single pod with a single containeralways: always show the prefixoff: never show the prefix
$ kt deploy foo --prefix=always
$ kt deploy foo --prefix=off
Using Homebrew:
$ brew tap knight42/tap
$ brew install knight42/tap/kt
Or download from the release page.