robinovitch61 / kl

An interactive Kubernetes log viewer for your terminal.
MIT License
83 stars 0 forks source link

kl

Latest Release GoDoc Build Status

An interactive Kubernetes log viewer for your terminal.

tree view of containers logs view single log help


Comparable to:

Usage

Install and run kl in a terminal. See kl --help for all options.

Press ? in any view to see keyboard shortcuts specific to the current view and across the application.

Examples:

# Use the current kubernetes context. If context namespace doesn't exist, uses `default`
kl

# Use context `my-context`, all namespaces
kl --context my-context -A

# Use contexts `my-context` & `other-context`, namespaces `default` & `other-ns` in each
kl --context my-context,other-context -n default,other-ns

# Auto-select all containers in a deployment containing the word `nginx`
kl --mdep nginx

# Auto-select all containers with the exact name of `my-container`
kl --mc "^my-container$"

# Ignore all containers with the exact name of `my-sidecar`
kl --ic "^my-sidecar$"

# Start on the logs page, ordered by timestamp descending, showing logs from 10 minutes ago onwards
kl --mc "^my-container$" -l -d --since 10m

Installation

The following installation options are available:

# homebrew
brew install robinovitch61/tap/kl

# upgrade using homebrew
brew update && brew upgrade kl

# nix-shell
# ensure NUR is accessible (https://github.com/nix-community/NUR)
nix-shell -p nur.repos.robinovitch61.kl

# nix flakes
# ensure flake support is enabled (https://nixos.wiki/wiki/Flakes#Enable_flakes_temporarily)
nix run github:robinovitch61/nur-packages#kl

# arch linux
# PKGBUILD available at https://aur.archlinux.org/packages/kl-bin
yay -S kl-bin

# with go (https://go.dev/doc/install)
go install github.com/robinovitch61/kl@latest

# windows with winget
winget install robinovitch61.kl

# windows with scoop
scoop bucket add robinovitch61 https://github.com/robinovitch61/scoop-bucket
scoop install kl

# windows with chocolatey
choco install kl

You can also download prebuilt releases and move the unpacked binary to somewhere in your PATH.

Development

kl is written with tools from Charm.

Feature requests and bug reports are welcome.

To manually build the project:

git clone git@github.com:robinovitch61/kl.git
cd kl
go build  # outputs ./kl executable

Running a an example flask + postgres + nginx setup in a local k3d cluster for testing locally:

k3d cluster create test
k3d cluster create test2
kubectl --context k3d-test apply -f ./dev/deploy.yaml
kubectl --context k3d-test2 create namespace otherns
kubectl --context k3d-test2 apply -f ./dev/deploy.yaml -n otherns

# view both clusters and all namespaces in kl
kl --context k3d-test,k3d-test2 -A

# access the application's webpage
kubectl -n otherns port-forward services/frontend-service 8080:80
open http://localhost:8080

# browser console one-liner to click button every second to generate logs
setInterval(() => { document.getElementsByTagName("button")[0].click();}, 1000);

# or make requests directly to flask from the terminal
kubectl port-forward services/flask-service 5000:5000
curl http://localhost:5000/status

Manually Specify the kl Version at Build Time

If necessary, you can manually specify the output of kl --version at build time as follows:

go build -ldflags "-X github.com/robinovitch61/kl/cmd.Version=vX.Y.Z"

In this case, you're responsible for ensuring the specified version matches what is being built.