In previous articles I showed how to setup Kubernetes in vSphere and how to deploy vSphere pods and Tanzu Kubernetes clusters. In this article I’m introducing some tools that will make your more efficient with kubectl, your cockpit to control Kubernetes.
In this article my base system is CentOS 8.2, most of the tools I discuss are also available for other OSes and follow a similar installation procedure.
Install kubectl
The first tool we need to get started is of course kubectl. Kubectl is available for download from your vSphere environment after you’ve created your first namespace in the vSphere Webclient.
Open the link and copy the download link for (in this example) the linux version of kubectl.
Now download the vsphere-plugin file (which contains kubectl) and verify the contens.
wget https://172.16.101.129/wcp/plugin/linux-amd64/vsphere-plugin.zip --no-check-certificate wget https://172.16.101.129/wcp/plugin/linux-amd64/sha256sum.txt --no-check-certificate sha256sum --check sha256sum.txt < vsphere-plugin.zip
Now unzip the file and copy the contents of /bin/ to /usr/local/bin (or another location that is appropriate) and check if kubectl is working.
unzip vsphere-plugin.zip sudo cp ./bin/* /usr/local/bin kubectl version --client
Configure kubectl completion
A next step is to configure kubectl completion to automatically complete your kubectl commands. The installation procedure for kubectl completion is available via
kubectl completion -h
First install bash-completion if it’s not yet available on your system:
sudo yum install bash-completion
Now configure kubectl completion following this procedure:
source <(kubectl completion bash) kubectl completion bash > ~/.kube/completion.bash.inc
You might want to login to your Kubernetes cluster once, so the .kube directory is created.
printf " # Kubectl shell completion source '$HOME/.kube/completion.bash.inc' " >> $HOME/.bash_profile source $HOME/.bash_profile cat ~/.bash_profile
That’s it!
Install kubectx + kubens power tools
Two other nice tools are kubectx and kubens. Kubectx is used to switch between contexts (these are the namespaces defined in the vSphere WebClient), while kubens is used to switch between (k8s) namespaces. Check out the Ahmet’s GitHub site for more information.
Depending on your OS/distro there are various installation options.
Install the tools through Homebrew is recommend and available for different OSes:
brew install kubectx
Don’t forget to source the auto completion scripts and add them to bashrc or bash_profile:
source /home/linuxbrew/.linuxbrew/etc/bash_completion.d/kubens source /home/linuxbrew/.linuxbrew/etc/bash_completion.d/kubectx
Kube-ps1 kubernetes prompt
Kube-ps1 is a script that lets you add the current Kubernetes context and namespace to your (bash/zsh) prompt.
brew install kube-ps1
Add the following lines to bashrc to change your prompt:
source "/home/linuxbrew/.linuxbrew/opt/kube-ps1/share/kube-ps1.sh" PS1='$(kube_ps1)'$PS1
You can turn on/off this prompt with kubeon and kubeoff.
K9S
K9S is an alternative Kubernetes CLI, “to manage your clusters in style”.
K9s provides a terminal UI to interact with your Kubernetes clusters. The aim of this project is to make 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 your observed resources.
Again brew will help your here with the installation.
brew install k9s
Now start k9s
Some of the features of K9S are:
- Track real time activities;
- Track your cluster metrics;
- Zoom into errors;
- and more.
Check out the k9s documentation to learn more!
Octant
Another really interesting tool is Octant. It’s providing a browser-based UI giving visibility on how applications are running. More on Octant in another post, for now check this article by William Lam.
@projectoctant is another awesome K8s UI. Check out https://t.co/wuwxIJtcJa for full list that I did awhile back this year
— William Lam (@lamw.bsky.social | @lamw@vmst.io) (@lamw) November 17, 2020
Also don’t forget to checkout this lesson on kube.academy to learn more about some of these tools.