k9s-the best Kubernetes CLI to manage your cluster in style

You can download this article in PDF format via the link below to support us.
Download the guide in PDF formatturn off

How do you manage a Kubernetes cluster? Did you log in to the dashboard to view Pod, network policy, and other aspects? That’s cool, but today our task is to make you consider another option, especially if you have a soft spot for the terminal and missed it on the dashboard.

K9s provides a terminal UI to interact with your Kubernetes cluster. The purpose of this project is to simplify the process of browsing, observing and managing applications in the field. K9s continuously monitors Kubernetes changes and provides follow-up commands to interact with the resources you observe.

The function of k9s

  • k9s provides information at your fingertips: tracking real-time activities of resources running in a Kubernetes cluster.
  • Standard or CRD?: Process Kubernetes standard resources and custom resource definitions.
  • Cluster metrics: Track real-time metrics associated with resources such as Pods, containers, and nodes.
  • Super user welcome! : Provides standard cluster management commands, such as log, extension, port forwarding, and restart. You can also define your own command shortcuts for quick navigation through command aliases and hot keys. In addition, it also provides plug-in support to extend K9 to create your own cluster commands, and a powerful filtering mode to allow users to drill down and view workload-related resources.
  • Error scaling: Directly delve into the problem of cluster resources.
  • Skinnable and customizable: define your own appearance through K9s skin. Customize/arrange the columns to be displayed according to each resource.
  • Narrow or wide? : Provides a switch to view the minimum or complete resource definition
  • MultiResources view: Provides an overview of cluster resources through Pulses and XRay views.
  • k9s has your RBAC!: It supports viewing RBAC rules, such as clusters/roles and their associated bindings. Reverse lookup can assert what the user/group or ServiceAccount can perform on the cluster.
  • Built-in benchmark test: You can benchmark the HTTP service/pod directly from K9s to understand the running status of the application and adjust the resource request/limit accordingly.
  • Resource graph traversal: K9s can easily traverse Kubernetes resources and related resources.

Overview

K9s is multi-platform, so it can be used on Linux, macOS and Windows platforms. In short, there is no reason not to let it run in your environment and guess what it is, we will see how to install it at this moment.

Install K9s

K9s has been mentioned in multiple platforms, the next section will introduce how to install it on some popular distributions as well as Windows and macOS. let’s start.

Install k9s on macOS

If you are a Mac person, chances are you will know Homebrew and you will install k9s through it. It’s as simple as a homebrew program, the following is the only command you need to run.

brew install k9s

Via Homebrew for macOS or Brew for Linux

If needed, you can also use MacPorts. The MacPorts project is an open source community project aimed at designing an easy-to-use system to compile, install and upgrade open source software based on the command line, X11 or Aqua on the Mac operating system.

sudo port install k9s

Install on Arch Linux

To get k9 on your favorite Arch Linux computer, pacman will provide it for you. Just run the following command:

pacman -S k9s

Install k9s on OpenSUSE Linux distribution

Okay, okay, OpenSUSE guys! You are also completely covered here. As shown below, install K9 through the beautiful zypper.

zypper install k9s

Install k9s on Windows

As you can imagine, installing k9s on Windows is very simple. You can use Scoop or my favorite Chocolatey.

Via Scoop for Windows

Install k9s through Scoop as follows

scoop install k9s

Via Chocolatey for Windows

Install k9s through Chocolatey as follows

choco install k9s

If you don’t have Chocolatey, you can check out the “Use Chocolatey to Manage Windows Applications from the Command Prompt (CLI)” guide.

Install k9s via GO install

The development version of k9s will take effect!

go get -u github.com/derailed/k9s

You can also build K9 from source code

K9s is currently using go v1.14 or higher. Follow the steps below to install Go v1.15.2 on Linux.

wget https://dl.google.com/go/go1.15.2.linux-amd64.tar.gz
sudo tar -C /usr/local -xf go1.15.2.linux-amd64.tar.gz
$ vim ~/.bash_profile
export PATH=$PATH:/usr/local/go/bin

Then get the file to keep the configuration.

source ~/.bash_profile

In order to build K9 from source, you must clone the repository before proceeding.

cd ~
git clone https://github.com/derailed/k9s.git
cd ~/k9s

Build and run the executable file

$ make build && ./execs/k9s

go: downloading k8s.io/client-go v0.18.8
go: downloading k8s.io/apimachinery v0.18.8
go: downloading k8s.io/metrics v0.18.8
go: downloading gopkg.in/yaml.v2 v2.2.8
go: downloading k8s.io/api v0.18.8
go: downloading k8s.io/klog v1.0.0
go: downloading github.com/sahilm/fuzzy v0.1.0
go: downloading github.com/gdamore/tcell v1.3.0
go: downloading github.com/derailed/popeye v0.8.10
go: downloading github.com/hashicorp/golang-lru v0.5.1
go: downloading sigs.k8s.io/structured-merge-diff/v3 v3.0.0
go: downloading github.com/fvbommel/sortorder v1.0.1

When you are done, you should see a shared interface below.

You will notice that the Kubernetes cluster information was not captured when k9s was started, which brings us to the next important step.

Add Kubernetes configuration file for K9s

The good news about k9s is that it looks in the default directory where the kubeconfig file is usually located. That is “~/.kube”. If you have a kubeconfig file for the cluster, just create the directory and copy the configuration file in it.

mkdir ~/.kube
cp config ~/.kube

After that, you can start k9s, and when you see the captured Kubernetes cluster details means that K9s is connected to your cluster, we can make sure that your face will smile to your satisfaction. In the k9s clone file, run the exec command again:

cd ~/k9s
./execs/k9s

k9s-the best Kubernetes CLI to manage your cluster in style

Use K9s

Now, after you have set up K9 and successfully connected it to Kubernetes, you can use a few keyboard shortcuts to start interacting with the cluster.

Show all pods

If you want to display all panes in all namespaces, you can press a simple keyboard key. You only need to press zero (0), and all of your ad podcasts will be displayed as follows.k9s-the best Kubernetes CLI to manage your cluster in style

Log showing pods

To display the log for a given Pod, you will need to use the up/down keyboard keys to highlight it, and then press the letter “l” to get the log. Quite intuitive! The log generated by the pod will drop as shown below.k9s-the best Kubernetes CLI to manage your cluster in style

After viewing the log and want to go back, press Esc.

Show alias

When you want to execute multiple Kubernetes commands in one session, aliases will make your life easier. To view the alias, use the (Ctrl + a) keyboard combination.k9s-the best Kubernetes CLI to manage your cluster in style

Execute to pod

Another thoughtful feature of the k9s out of the box is that it can be packaged into a Pod using a keyboard key. It really makes your work as easy as possible. To pack into a pod, use the up/down keys to highlight it and press the “s” key.

Describe a pod

If you want to investigate the configuration of a resource, the description pane can provide comprehensive information/details about the resource. K9s simplifies this process by reducing the same operations as other functions, just pressing a key. To describe your ad podcast, use the up/down keyboard keys to highlight it, and then press the “d” keyboard key.k9s-the best Kubernetes CLI to manage your cluster in style

Show all keys (help)

In short, to view all available keys, you need to press a key, which is the question mark (?). You will share the useful keys in the screenshot below.k9s-the best Kubernetes CLI to manage your cluster in style

in conclusion

Managing your Kubernetes cluster has never been as easy and fun as using k9s. In addition to the content covered in this guide, it has many other functions. You can delete kubernetes resources, check cluster metrics, etc.For more detailed information about this tool, check out its tool GitHub official page.

That being said, it’s time to thank you for your visit and stay the course. We hope the content shared above will be helpful to you. For other guidelines similar to this, please check below:

  • How to install GitHub CLI (gh) windows on Linux
  • Top terminal-based monitoring tool for Linux
  • Use Active Directory to authenticate Kubernetes dashboard users
  • Use Kubernetes Operational View to monitor Kubernetes deployment
  • How to perform Git clone in Kubernetes Pod deployment

You can download this article in PDF format via the link below to support us.
Download the guide in PDF formatturn off

Sidebar