Basic setups for working with Kubernetes

When working with kubernetes (maybe in a CKA exam), you work with terminal most of the time. Configuring the environment properly is vital to save you time. Here are things I do first when entering a new environment (Kubernetes Playground | Katacoda, for example).

Enable bash completion

Honestly, I don’t use this much. However, occasionally, it saves me some precious time so here you go:

echo 'source <(kubectl completion bash)' >>~/.bashrc
kubectl completion bash >/etc/bash_completion.d/kubectl

In addition, I would love to have k as an alias of kubectl:

echo 'alias k=kubectl' >>~/.bashrc
echo 'complete -F __start_kubectl k' >>~/.bashrc

Now I can type k get p and press tab twice, there are some nice suggestions:

Configure VIM

You have some choices when it comes to text editor in the terminal. For me personally, I use Vim. There are some basic configurations I need to set on every new environment:

  • Tab is 2
  • No tab, only spaces
  • Cursor column (super helpful when working with indentation)

So, here is my settings for VIM

set tabstop=2
set number
set shiftwidth=2
set expandtab
set cursorcolumn
set paste
set autoindent
set smartindent
colorscheme desert

With all that set, I’m ready to work on any tasks 😉

Quick copy/paste for all of those

You can copy all these commands and paste directly to your terminal to get similar effects:

echo 'source <(kubectl completion bash)' >>~/.bashrc
kubectl completion bash >/etc/bash_completion.d/kubectl
echo 'alias k=kubectl' >>~/.bashrc
echo 'complete -F __start_kubectl k' >>~/.bashrc
echo "set tabstop=2 number shiftwidth=2 expandtab cursorcolumn paste autoindent smartindent" > ~/.vimrc
echo "colorscheme desert" >> ~/.vimrc

Leave a Comment