Member-only story

Kubectl : be efficient with your CLI

2 min readDec 15, 2024

When a company adopts kubernetes, it’s cool. But no day without run a kubectl to debug or troubleshoot, that’s the reality.

So to be efficient in your day to day, you need to add some little tools arround your kubectl command line.

1- Add the autocompletion

Of course add the autocompletion is a good start.

sudo apt-get install bash-completion
echo "source <(kubectl completion bash)" >> ~/.bashrc
echo "complete -F __start_kubectl k" >> ~/.bashrc
source ~/.bashrc

With it’s commands, you add autocompletion for kubectl and for the k alias.

2- Add some aliases kubectl

Common aliases are usually :

alias k='kubectl'
alias kcc='kubectl config current-context'
alias kg='kubectl get'
alias kga='kubectl get all --all-namespaces'
alias kgp='kubectl get pods'
alias kgs='kubectl get services'
alias ksgp='kubectl get pods -n kube-system'
alias kuc='kubectl config use-context'

3- Add the kubernetes context in your prompt

Really useful to not break your production environment :)

--

--

Xavier Pestel (Xavki)
Xavier Pestel (Xavki)

Written by Xavier Pestel (Xavki)

Microservices architecture and opensource. I’m maintainer of xavki https://youtube.com/c/xavki-linux about opensource. My blog : https://xavki.blog/

No responses yet