Why So Serious : Setting up a Serious Kubernetes Terminal

CLI tools a growing K8S team needs .

Tushar Sappal
Tech Bits
5 min readJun 16, 2019

--

The blog covers tools that are used widely within K8S community .

Kubernetes comes pre-packaged with an outstanding CLI. For basic operations, it works wonderfully. But, when one needs to do something quickly, co mplexity increases.

Having a fully kitted terminal will rapidly speed up the time it takes to get to the root of an issue. It forms a fundamental part of your Swiss army knife to manage and administer the Kubernetes cluster.

ZSH

ZSH is an outstanding, open source wrapper around the standard OSX terminal. It is more feature rich and intuitive and the plugins you can install are fantastic. Some of these tools listed make the assumption you have ZSH installed.

ZSH Link :- https://ohmyz.sh/

K9S

K9s provides a curses based terminal UI to interact with your Kubernetes clusters. K9S makes it easier to navigate, observe and manage your applications in the wild. K9s continually watches Kubernetes for changes and offers subsequent commands to interact with observed resources.

You can SSH straight into pods with a single key press, view logs, delete resources , describe pods. K9S provides outstanding access for the most common operations you’ll be performing. This is a staple for any engineer using kubernetes.

K9S Sample Screen for a minikubesetup

K9S Link:- https://github.com/derailed/k9s

Kubectx and Kubens

Since it very rare that one will have one single cluster to work upon . Switching between these is as simple as

But with this, there are some prerequisites:

  • You need to know the name of the cluster before you run.
  • There is another, similar set-context command that could trip you up.

kubectx presents a simpler alternative to this. If you run kubectx on its own, it will list out all of the contexts in your .kube/config file. You can then provide the name of the context you’re interested in:

No need to remember all the contexts, no need to manually check files and no possibility of getting the wrong command. Nice and simple. Combined with k9s, this offers a lot of navigability from your CLI with minimal key presses.

The following image shows a good depiction of how kubectx works

Kubectx in action

Once you’re flitting around contexts, you may want to dig into a specific namespace. Once again, it’s very common to have more than a few namespaces in your cluster. for that we have another tool ( from the same repo )kubens. It’s the same as kubectx, only for namespaces.

Now all of your commands run against the kube-system namespace, by default. You can also run kubens without anything else to see a list of your namespaces.

The following image shows a good depiction of how kubens works

Kubens in Action

kubectx and Kubens Link :- https://github.com/ahmetb/kubectx

Kubeps1

So, you can switch between contexts and namespaces. But how do you know which one you’re currently aimed at? It’s a pain to keep checking. At the moment, to find out you’d need to run:

To remove this, ps1 is a zsh plugin that will automatically show you your current context and namespace:

I’m pointing at my minikube context and the default namespace

Now you can see which namespace and context you’re pointing out without running a single command. It’s also highly configurable too — you can turn off namespace or context, if you’re only interested in one of them, or you can use kubeoff to disable the whole thing entirely.

The following image shows how kubeps1 works

Kubeps1 in Action

Kubeps1 Link :- https://github.com/jonmosco/kube-ps1

Kubetail

Bash script that enables you to aggregate (tail/follow) logs from multiple pods into one stream. This is the same as running “kubectl logs -f “ but for multiple pods.

First find the names of all your pods:

This will return a list looking something like this:

To tail the logs of the two “app2” pods in one go simply do:

To tail only a specific container from multiple pods specify the container like this:

You can repeat -c to tail multiple specific containers:

To tail multiple applications at the same time seperate them by comma:

For advanced matching you can use regular expressions:

Kubetail Link :- https://github.com/johanhaleby/kubetail

Popeye

Popeye is a utility that scans live Kubernetes cluster and reports potential issues with deployed resources and configurations. It sanitizes your cluster based on what’s deployed and not what’s sitting on disk. By scanning your cluster, it detects misconfigurations and ensure best practices are in place thus preventing potential future headaches. It aims at reducing the cognitive overload one faces when operating a Kubernetes cluster in the wild.

Popeye is a readonly tool, it does not alter any of your Kubernetes resources in any way!.

The following screenshots will help you understand what popeye is capable of

Popeye in Action against a test cluster

Popeye Link :- https://github.com/derailed/popeye

--

--