VMware : Tips of the week #4

We want to share with you some concepts, helpful commands, and gotchas that we have come across during the first few days within the Kubernetes world.  

Kubernetes uses a command-line tool called kubectl for running commands against clusters,  you may find yourself frustrated by the time spent typing repetitive commands.

This article will highlight tips used to simplify the usage of kubectl and save you time.

Shell aliases can be used to shorten all shell commands and not just those related to kubectl. Begin by creating a file in your $HOME directory specific for kubectl aliases, and add all helpful aliases for kubectl such as :

Here top 10 shell aliases for 𝐤𝐮𝐛𝐞𝐜𝐭𝐥:

  • alias k=’kubectl’
  • alias kgns=’kubectl get namespaces’
  • alias kgc=’kubectl config get-contexts’
  • alias kuc=’kubectl config use-context’
  • alias kg=’kubectl get’
  • alias kgn=’kubectl get nodes’
  • alias kgp=’kubectl get pod’
  • alias kgpall=”kubectl get pods –all-namespaces”
  • alias krm=”kubectl delete’
  • alias kgsvc=’kubectl get service’

And then edit your .bashrc file with the following:

$ [ -f ~/.kubectl_alias ] && source ~/.kube_alias

If you need to list all your aliases just run: 

$ alias

kubectl shell autocompletion is another way to save time. To configure shell autocompletion on centos just run:

$ yum install -y bash-completion
 $ source <(kubectl completion bash) 
 $ echo "source <(kubectl completion bash)" >> ~/.bashrc

If you get a message with the error below: 

$ kubectl bash: _get_comp_words_by_ref: command not found

You can fix this with these commands:

$ source /etc/profile.d/bash_completion.sh  
 $ source <(kubectl completion bash)*

If you are not a CLI champion, one of the tool you can use is Octant from VMware.

Octant is a web interface for Kubernetes that gives you the visibility of your Kubernetes cluster and applications running on it.

Enjoy!

Leave a Reply

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