kube shell - Feature Rich Tool for Easy use of Kubernetes CLI

kube shell kubernetesToday we will show how to install and use the kube-shell. It is a Python and Go based shell that offers auto-completion, history and many other goodies for Kubernetes' well known kubectl command. It still uses kubectl, it is by no means a replacement for it, but it can come in handy for productivity and learning.

Prerequisites:

  • Linux destkop or laptop
  • VirtualBox
  • Python with pip installed

Installing VirtualBox

As we are going to try kube-shell on a local minikube cluster, we need VirtualBox. Installing VirtualBox for your distro should be easy, but still we are going to provide heads up for most popular ones:

On Fedora with RPMFusion enabled

sudo dnf install VirtualBox

On Ubuntu

sudo apt-get install virtualbox

On CentOS with RPMfusion enabled

sudo yum install VirtualBox

Installing kubectl and minikube and kubectl

Installing the Minikube is next step. The following command will fetch you a minikube binary and put it into in /usr

curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && chmod +x minikube

And this one will move it to your path so you can call it without specifying full path of the binary.

sudo mv minikube /usr/local/bin/

You will off course need the kubectl binary as well. So we can fetch it with this command

curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl && chmod +x kubectl

And then put kubectl to the path as well.

sudo mv kubectl /usr/local/bin/

Creating a cluster

After we have all this set up, we can create a minikube cluster on our machine. Make sure you don't have KVM running as VirtualBox conflicts with it, and then run following command.

minikube start

You need an active internet connection for this to work, as files need to be fetched from internet to install the OS on a VirtualBox VM that will be our cluster. Your output should be something like this gif:

When cluster is up, you can run get nodes command to see if it is working. The output should be similar to this:

$ kubectl get nodes
NAME STATUS AGE VERSION
minikube Ready 7m v1.7.0

Additionally, there is command minikube status

$ minikube status
minikube: Running
localkube: Running
kubectl: Correctly Configured: pointing to minikube-vm at 192.168.99.100

Installing kube-shell

Now when we have cluster up and running, we will install kube-shell. As we mentioned, it is a Python program and it is installed through Python package manager, called pip. On some Linux distros you can actually have Python installed without pip. So make sure you have both pip and Python.

On centOS with EPEL enabled , you run this command

sudo yum install python-pip

On Ubuntu

sudo apt-get install python-pip

On Fedora

sudo dnf install python-pip

After you make sure pip is installed, you simply run this command

sudo pip install kube-shell

And here we go, kube shell is installed!

Using kube-shell

First of all, lets install some app to our cluster. That can be hello-minikube app

kubectl run hello-minikube --image=gcr.io/google_containers/echoserver:1.7 --port=8080

Next lets enter kube-shell with simple kube-shell command.

In kube-shell lets expose deployment to outside world

kube-shell> kubectl expose deployment hello-minikube --type=NodePort

Let's see how kube-shell does it's magic on this GIF.

You need only to start writing sub-command after kubectl and list of available completions will show. Also after word "deployment" you get available deployments you can expose. You pick them from drop down menus as well.  After that, you can type

minikube service hello-minikube --url
http://192.168.99.100:31698

And you will get url which you can visit to view the app. Next let's scale app and see how kube-shell helps us delete pods.

kube-shell> kubectl scale deployment --replicas=5 hello-minikube

And we will use kube-shell autocomplete functionality to pick one of replicas for deletion.

Using the kube-shell does not need further examples, it is completely intuitive. You can cycle through history using up arrow key, or you can cycle auto-completion options while typing using tab key or the up and down arrow keys.  To exit kube-shell and go back to bash just type exit. The kube-shell still has some unfinished features, most notably does not complete parameters after -- mark like for example --type=NodePort. But it is completely open for contribution and available on github so any Python hacker can improve it. With that, we end for this article.

About Mihajlo Milenovic

Miki is a long time GNU/Linux user, Free Software advocate and a freelance system administrator from Serbia. Got introduced to GNU/Linux in year 2003 on old AMD Duron computer, and since than always eager to learn new stuff about this system. From 2016 writes for Linoxide to share his experiences with wider audience

Author Archive Page

Have anything to say?

Your email address will not be published. Required fields are marked *

All comments are subject to moderation.