protokol
is a command line tool to watch for pods and storing their logs as text files
on your local machine. It's primarily intended to be used in test scenarios where you
need to gather logs of many different, possibly restarting or reconciled pods at the
same time.
You can download a binary for the latest release on GitHub or install protokol via Go:
go install go.xrstf.de/protokol
Usage of protokol:
-c, --container stringArray Container names to store logs for (supports glob expression) (can be given multiple times)
--events Dump events for each matching Pod as a human readable log file (note: label selectors are not respected)
--events-raw Dump events for each matching Pod as YAML (note: label selectors are not respected)
-f, --flat Do not create directory per namespace, but put all logs in the same directory
--kubeconfig string kubeconfig file to use (uses $KUBECONFIG by default)
-l, --labels string Label-selector as an alternative to specifying resource names
--live Only consider running pods, ignore completed/failed pods
--metadata Dump Pods additionally as YAML (note that this can include secrets in environment variables)
-n, --namespace stringArray Kubernetes namespace to watch resources in (supports glob expression) (can be given multiple times)
--oneshot Dump logs, but do not tail the containers (i.e. exit after downloading the current state)
-o, --output string Directory where logs should be stored
--prefix string Prefix pattern to put at the beginning of each streamed line (pn = Pod name, pN = Pod namespace, c = container name) (default "[%pN/%pn:%c] >>")
--stream Do not just dump logs to disk, but also stream them to stdout
-v, --verbose Enable more verbose output
protokol '*'
This is the BFG: it will watch all Pods in all namespaces and stream the logs for each running container to a text file in your disk. Don't do this, you do not want to kill the apiserver with a gazillion streams.
protokol -n kube-system -n 'cluster-*'
You can restrict the Pods to a set of namespaces. Wildcards are allowed.
protokol -l 'foo=bar'
Label selectors work just as you would expect.
protokol 'kube-*' 'coredns-*' 'etcd-*'
You can give multiple name patterns, placeholders are allowed.
protokol -c 'test*' 'kube-*' 'coredns-*' 'etcd-*'
You can restrict the container names using -c
. This flag can be given multiple times and also supports wildcards.
protokol -o test 'kube-*' 'coredns-*' 'etcd-*'
By default protokol will create a protokol-%Y%m%dT%m.%h%s
directory whenever you invoke it, but you can also specify
a directory yourself.
protokol -o test -f 'kube-*' 'coredns-*' 'etcd-*'
By default protokol will create one directory per namespace. With -f
(--flat
) you can disable this behaviour.
protokol --stream 'etcd-*'
This will not just dump the logs to disk, but also stream them to stdout.
MIT