guettli/getklogs

Get Kubernetes Logs

★ 0Forks 0GoGitHub ↗Compare

README

getklogs

getklogs fetches workload and pod logs and sorts them by Kubernetes timestamp.

Repository: https://github.com/guettli/getklogs

Run

You can run directly:

go run github.com/guettli/getklogs@latest my-deployment

Install

go install github.com/guettli/getklogs@latest

Usage

Fetch logs for Kubernetes workloads and pods and sort them by Kubernetes timestamp.

Here, "workload" means a Deployment, DaemonSet, or StatefulSet.

If [term] is given, targets are matched case-insensitively via *term* across workload name,
namespace, and kind. If term does not match exactly one workload, an interactive selection
appears so you can choose a workload.

By default, getklogs fetches logs from last 3h.

Use --kubeconfig to set an explicit kubeconfig path.
By default, getklogs uses the KUBECONFIG environment variable when it is set.

Use --node to only include pods scheduled on nodes matching the given glob, for example *node*.
Use --meta to include metadata such as source_pod and source_container in the output.
Use --per-container to create one output file per container instead of joining all lines for the target.
Use --follow to stream new log lines as they arrive; it implies --stdout.

By default, getklogs writes the result to a timestamped file such as:
  deployment-name--namespace-YYYY-MM-DD_HH-MM-SSZ.log

By default, all log lines for the selected target are joined and sorted by time.

Usage:
  getklogs [term] [flags]
  getklogs [command]

Examples:
  getklogs
  getklogs kubeadm-bootstrap
  getklogs --since 0s kubeadm-bootstrap
  getklogs -o raw --tail 50 -n kube-system coredns
  getklogs --pod apiserver
  getklogs --node '*worker*' --all
  getklogs --meta frontend
  getklogs --per-container frontend
  getklogs --follow frontend
  getklogs --all
  getklogs --outdir /tmp/getklogs --all
  getklogs --stdout --tail 50 -n kube-system coredns
  cat foo.log | getklogs tojson

Available Commands:
  completion  Generate the autocompletion script for the specified shell
  help        Help about any command
  tojson      Convert stdin log lines into json, yaml, or raw output

Flags:
      --all                 Process all matching targets. No interactive workload selection.
      --follow              Follow logs and stream new lines as they arrive (implies --stdout)
  -h, --help                help for getklogs
      --kubeconfig string   Path to kubeconfig file (default: use KUBECONFIG when set)
      --meta                Include metadata such as source_pod and source_container in the output
  -n, --namespace string    Kubernetes namespace (optional; if omitted: all namespaces)
      --node string         Only include pods on nodes matching this glob pattern, for example *node*
      --outdir string       Output directory (default: current directory)
  -o, --output string       Output format: json, yaml, or raw (default "json")
      --per-container       Create one output file per container instead of one combined file per target
      --pod                 Match pods by name instead of workloads
      --since duration      Return logs newer than a relative duration like 5s, 2m, or 3h. Use 0s for all available logs (default 3h0m0s)
      --stdout              Write output to stdout instead of creating files
      --tail int            Only include the last N combined log lines per target; with --per-container, per container
  -v, --version             version for getklogs

Use "getklogs [command] --help" for more information about a command.

Feedback

Feedback is welcome. Just open and issue and tell me what you think about getklogs.

Related

Contributors

guettli

Issues