Viewing logs of Kubernetes pods using lnav. This is written in bash script.
- I am sick of copying long auto-generated pod name before pasting into
kubectl logscommand. K9s can help here. - My eyes hurt when looking at the wall of log text in the terminal
- I want to filter/search the logs in a professional log viewer
- I want to play with shell script
This tool depends on fzf, lnav and kubectl.
View logs of your pod/container using lnav
Add this to your .bashrc or .zshrc
function klg () {
<Path-to-your-cloned-repo>/klg/klg.sh $@
}
Start /bin/sh inside your pod and let you run any shell command as you want.
Add this to your .bashrc or .zshrc
function ksh () {
<Path-to-your-cloned-repo>/klg/ksh.sh $@
}
Execute a shell command inside a k8s pod
Add this to your .bashrc or .zshrc
function ke () {
<Path-to-your-cloned-repo>/klg/ke.sh $@
}
klg [options]
ksh [options]
ke [options]
Available option:
-n: Keyword to fuzzy search for k8s namespace. Ignored when-Nis specified.-p: Keyword to fuzzy search for k8s pod. Ignored when-Pis specified.-c: Keyword to fuzzy search for container. Ignored when-Cis specified.-N: Exact namespace (no searching)-P: Exact pod name (no searching)-C: Exact container name (no searching)
If namespace options are not provided, $K8S_DEFAULT_NS will be used, by default, it is default.
If pod options are not provided, the user will be asked to select pod on a fuzzy search popup.
If container options are not provided for multi-container pods, the user will be asked to select container on a fuzzy search popup.
Example:
klg
klg -n my-nsp
klg -n my-namespace -p my-pod -c my-container
K8S_DEFAULT_NS=my-default-ns klg -p mypd -c myctn
ksh -p my-pod
ksh -n my-nsp -p my-pod -c my-container
ke -n my-nsp -p my-pod -- my-command the arg list
Finish following features:
- Fuzzy search for k8s namespace/pod/container
- Viewing logs in lnav
- Using default namespace
defaultor$K8S_DEFAULT_NS - Handle error cases and return error code (e.g. pod not found, namespace not found)
- Auto-select the only container in pod
If you are a fisher (as I am), please refer to this file.
