Skip to content

samisalkosuo/kubeterminal

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

KubeTerminal

KubeTerminal is helper tool for Kubernetes and/or OpenShift. The idea is provide a simple and quick tool to get the basics out of Kubernetes environment.

KubeTerminal is complementing, not replacing, existing kubectl/oc and shell.

Features include:

  • Uses the shell and kubectl-command.

  • List pods in namespace and/or node.

  • List services, secrets and other resources in namespace.

  • See pod logs.

  • Describe pods.

    • Get YAML and JSON descriptions.

    • Get labels.

  • Execute command in a pod.

  • View configmaps and secrets.

    • Decode base64 values.

    • Use openssl to view secret values that are TLS certificates.

  • Option for single executable, for easy installation.

  • Colors, if terminal supports them.

KubeTerminal_05

Installation and usage

  • Python 3.

    • Python 3.11.7 used for development.

    • Windows or Linux.

  • Clone/download this repo.

  • Install prereqs:

    • pip install -r requirements.txt

    • Install and configure kubectl or oc.

    • Install openssl in order to view certificates.

  • Login to Kubernetes/OpenShift cluster before using KubeTerminal.

  • Start KubeTerminal:

    • python kubeterminal.py

  • Basic commands:

    • refresh pod list: <ctrl-r>

    • tab: switch windows and refresh resource list

    • use tab to go to Pods-window and:

      • line up/down to select pod

      • describe pod: <ctrl-d>

      • show logs: <ctrl-l>

KubeTerminal help

Command line options

usage: kubeterminal.py [-h] [--no-dynamic-title] [--compact-windows]
                       [--even-more-compact-windows]
                       [--kubeconfig KUBECONFIGPATH [KUBECONFIGPATH ...]]
                       [--current-kubeconfig CURRENT_KUBECONFIG] [--oc]
                       [--no-help] [--print-help]

optional arguments:
  -h, --help            show this help message and exit
  --no-dynamic-title    Do not set command window title to show NS, node and
                        pod.
  --compact-windows     Set namespace, node and pod windows to more compact
                        size.
  --even-more-compact-windows
                        Set namespace, node and pod windows to even more
                        compact size.
  --kubeconfig KUBECONFIGPATH [KUBECONFIGPATH ...]
                        Set path(s) to kubeconfig auth file(s).
  --current-kubeconfig CURRENT_KUBECONFIG
                        Set path to current/active kubeconfig auth file.
  --oc                  Use oc-command instead of kubectl.
  --no-help             Do not show help when starting KubeTerminal.
  --print-help          Print KubeTerminal help and exit.

Terminal commands

=== 2024-02-02T12:28:38.462310 help ===
KubeTerminal

Helper tool for Kubernetes and OpenShift.

Output window shows output of commands.
"Selected pod/resource" is the resource where cursor is in the Resources window.

Key bindings:

ESC           - exit program.
TAB           - change focus to another window.
<alt-u>       - resource window up one line.
<alt-j>       - resource window down one line.
<alt-i>       - resource window page up.
<alt-k>       - resource window page down.
<alt-o>       - output window page up.
<alt-l>       - output window page down.
<alt-0>       - list available windows.
<alt-1>       - show pods.
<alt-2>       - show configmaps.
<alt-3>       - show services.
<alt-4>       - show secrets.
<alt-5>       - show statefulsets.
<alt-6>       - show replicasets.
<alt-7>       - show daemonsets.
<alt-8>       - show persistentvolumeclaims.
<alt-9>       - show persistentvolumes.
<alt-10>      - show deployments.
<alt-11>      - show storageclasses.
<alt-12>      - show jobs.
<alt-13>      - show cronjobs.
<alt-14>      - show roles.
<alt-15>      - show rolebindings.
<alt-16>      - show serviceaccounts.
<alt-17>      - show poddisruptionbudgets.
<alt-18>      - show routes.
<alt-19>      - show ingresses.
<alt-20>      - show nodes.
<alt-21>      - show customresourcedefinitions.
<alt-22>      - show namespaces.
<alt-c>       - show kubeconfig and context.
<alt-shift-l> - show logs of currently selected pod.
<alt-shift-r> - refresh namespace and node windows.
<alt-d>       - show description of currently selected resource.
<alt-y>       - show YAML of currently selected resource.
<alt-r>       - refresh resource (pod etc.) list.
<alt-g>       - to the end of Output-window buffer.
<alt-w>       - toggle wrapping in Output-window.
/             - search string in Output-window.

Commands:

help                                  - this help.
all                                   - show all resources in namespaces.
clip                                  - copy Output-window contents to clipboard.
cls                                   - clear Output-window.
context [<cxt_index>]                  - show current and available contexts or set current context.
decode <data key> [cert}              - decode base64 encoded secret or configmap value, optionally decode certificate.
delete [--force]                      - delete currently selected pod, optionally force delete.
describe                              - describe currently selected resource.
exec [-c <container_name>] <command>  - exec command in currently selected pod.
json                                  - get JSON of currently selected resource.
ku <cmds/opts/args>                   - execute kubectl in currently selected namespace.
kubeconfig [<config_index>]           - list kubeconfigs or set current config.
labels                                - show labels of currently selected pod.
logs [-c <container_name>]            - show logs of currently selected pod.
oc <cmds/opts/args>                   - execute oc in currently selected namespace.
save [<filename>]                     - save Output-window contents to a file.
shell <any shell command>             - executes any shell command.
top [-c | -l <label=value> | -n | -g] - show top of pods/containers/labels/nodes. Use -g to show graphics.
version                               - Show 'kubectl' and 'oc' version information.
window [<window name> | list]         - Set resource type for window. 'window list' lists available windows.
workers [-d]                          - get worker node resource allocation. Use -d to describe all worker nodes.
wrap                                  - toggle wrapping in Output-window.
yaml                                  - get YAML of currently selected resource.

Executable binary

Executable binary is used to provide easy way to distribute KubeTerminal to servers without Internet connection. PyInstaller can be to create the executable

Binary is created on system where you want to use the binary. For Windows binary, create the binary in Windows, for Linux, create the binary in Linux, and so on.

Create binary

Use the following commands create binary in the platform you are using:

  • Install PyInstaller

    • pip install pyinstaller

  • Create single file executable:

    • pyinstaller --onefile kubeterminal.py

  • Binary file is located:

    • dist/kubeterminal

    • if building on Windows, file has .exe suffix.

Screenshots

KubeTerminal_01
KubeTerminal_02
KubeTerminal_03

Background

I’m working with Kubernetes quite a lot and I found that there a few basic commands that I use very, very often. For example:

  • kubectl get pods

  • kubectl logs <pod name>

  • kubectl describe pod <pod name>

Writing these commands take time, and when in hurry, that time is noticeable.

I accidentally found Kubebox and immediately tried it. But authentication failed when using Kubernetes with self-signed certificate.

Kubebox idea haunted until I remembered the existence of Python Prompt Toolkit and remembered that it can be used to create full-screen terminal application.

I decided to make my own Kubebox, and I named it KubeTerminal :-)