K9s – UI tool to Manage Kubernetes Clusters In Style!

Introduction

K9s provides a terminal UI to interact with your Kubernetes clusters and all resources that are running on top of it. It simplify and increase both navigation and observability for your applications to control and manage all of them in single pane of glass. K9s continually watches Kubernetes for changes and offers subsequent commands to interact with your observed resources – and this is actually added value to DevSecOps administrators.

The official documentation can be found here: https://k9scli.io/. You will find there installation guide as well as sample commands and advanced configuration. So you have all in once place.

Prerequisites

To start playing with K9s you need to have a Kubernetes cluster and kubectl binary and that’s it. No more specific requirements are needed.

Main Advantages

  1. Efficiency: K9s consolidate cluster management tasks, offering quick access and real-time updates on resource status.
  2. Convenience: Its keyboard-centric approach with handy shortcuts saves time and effort compared to traditional GUI-based tools.
  3. Visibility: K9s provides detailed insights into the workings of your Kubernetes clusters, including pods, nodes, and other resources.
  4. Easy Debug: With features like log streaming and resource inspection, K9s simplifies troubleshooting in complex Kubernetes environments.
  5. Customization: Users can tailor the tool to fit their workflow with configurable views and commands.

Installation

Installation supports multiple OS types: Linux, Windows and MacOS. I will present how to do it on Linux machine of course.

You can perform the installation in several different ways:

  • via Webi
$ curl -sS https://webinstall.dev/k9s | bash
  • via Linux Brew
$ brew install derailed/k9s/k9s
  • via PacMan
$ pacman -S k9s

In my case I will choose Webi as this is simple one curl command to execute it. Once you execute it the output should be similar to the picture below.

After the installation you need to either close the terminal an reopen it or execute following command:

$ source ~/.config/envman/PATH.env

K9s keeps its configuration files under ~/.config/k9s/config.yaml. The default configuration will vary across operating system so be sure to read up on the default location if you choose not to set that environment variable. The main configuration file is named config.yaml and stores various K9s specific bits – below default values for Linux:

k9s:
  liveViewAutoRefresh: false
  screenDumpDir: /home/student/.local/state/k9s/screen-dumps
  refreshRate: 2
  maxConnRetry: 5
  readOnly: false
  noExitOnCtrlC: false
  ui:
    enableMouse: false
    headless: false
    logoless: false
    crumbsless: false
    reactive: false
    noIcons: false
    defaultsToFullScreen: false
  skipLatestRevCheck: false
  disablePodCounting: false
  shellPod:
    image: busybox:1.35.0
    namespace: default
    limits:
      cpu: 100m
      memory: 100Mi
  imageScans:
    enable: false
    exclusions:
      namespaces: []
      labels: {}
  logger:
    tail: 100
    buffer: 5000
    sinceSeconds: -1
    textWrap: false
    showTime: false
  thresholds:
    cpu:
      critical: 90
      warn: 70
    memory:
      critical: 90
      warn: 70

Of course you can review those defaults and change it accordingly – every single parameter cab be adjusted as you want.

Last commands to validate the installation are:

$ k9s version
$ k9s info

Both of them will show version installed and return information about the K9s runtime like logs, configs etc. Basically it will confirm that all is installed fine and K9s is ready to use.

K9s Usage

After installation, next step is to run the K9s and just use it through commands. I will demonstrate the screenshots for only few of them but below you can find the full list of most common, standard K9s shortcuts.

Let’s start and run K9s!

$ k9s

Default view is to see all Pods available in default Namespace. When you type “0” you will switch to --all-namespaces view but still only Pods objects.

To switch view by kind, you need to type “:deploy“. Then you will see the completion for a kind and automatically the output will adjust to the new object kind.

When you want to describe some resource, just select the resource on the list and type “d“.

As you can see I have selected the python-app deployment and once I click “d” I have it described.

You can also type “l” to see the Pod/Deployment logs, similar to this:

You can also sort the resources usage by CPU or Memory, to do so you need to type “Shift + C” or “Shift + M” respectively.

And that’s it more useful switches and shortcuts you have below – feel free to test them on your own.

  • : – Enter command mode
  • / – Initiate search
  • Tab/Shift + Tab – Switch between panels or tabs
  • Esc – Exit command mode or go back
  • ? – Open help menu
  • 0-9 – Switch between predefined resource views
  • Shift + L – Open list of last used resources
  • Ctrl + A – Select all text
  • Ctrl + E – Activate command line
  • Ctrl + F – Enter filter mode
  • Ctrl + R – Refresh resource
  • Ctrl + S – Save resource
  • Ctrl + W – Open a new tab
  • l – Show logs for selected pod
  • s – Shell access to the selected pod
  • e – Edit selected resource
  • d – Delete selected resource
  • y – Show YAML output for the selected resource
  • i – Show descriptions for the selected resource
  • x – Expand or collapse selected resources (e.g., containers in a pod)
  • Shift + C – Sort by CPU usage
  • Shift + M – Sort by Memory usage
  • Shift + A – Manage aliases
  • Shift + E – View last commands in command mode
  • Shift + F – Access favourites
  • Shift + H – Switch among all resources
  • Shift + K – Manage kubeconfig
  • :pod – Access the pod view
  • 01 – Predefined resource views shortcuts
  • <enter> – Enter or select a resource
  • <esc> – Escape or go back (used at the pod parent level)
  • /v2 – Filter command (example: filtering with version v2)
  • l – View logs of a pod
  • s – Access shell command line for a pod
  • /-l version=v2 – Filter command with a specific label (example)
  • :ns – Switch to the namespace view
  • Ctrl + D – Delete selected resource
  • :pulse – Access the pulse view (if available in the version)
  • :popeye – Run Popeye, a Kubernetes cluster sanitiser (if integrated)
  • :xray pod default – X-ray view for a specific pod in the default namespace

Conclusion

Managing Kubernetes clusters in daily basis can be really challenging, but K9s makes it significantly easier with its intuitive and powerful UI. This tool enhances productivity by offering real-time resource monitoring, easy navigation, and customizable commands and config, all within a visually appealing interface.

In this article I have presented how to install K9s, configure and use it. I hope you get familiar with K9s and you know and understand how it simplifies cluster management and accelerates troubleshooting.

In summary, K9s transforms Kubernetes management, combining functionality and style. Adopting K9s means mastering your Kubernetes clusters efficiently and effectively. Thank you for exploring K9s with me and stay tuned for more Kubernetes content soon!