Today 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.
- Linux destkop or laptop
- Python with pip installed
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
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.
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
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
sudo apt-get install python-pip
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!
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
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.