Kubectl tips and tricks

Thank you Aydarsh

I found very useful your set of tricks and tips and he has helped me a lot to define my own set and to figure it out the way I faced the exam.

I am sharing some of my thoughts on them.

First of all, I prefer to deal with a limited set of alias, easy to remember and that saves a lot of time. I also look for the very basic configuration of my editor (line number, tabs as spaces, etc). Choose the ones you think would help and practice with them all the time. I am listing below the ones that were useful for me.

{
  echo "set tabsize 2" | tee -a ~/.nanorc
  echo "set tabstospaces" | tee -a ~/.nanorc
  echo "set linenumbers" | tee -a ~/.nanorc

  alias k=kubectl
  alias kn='k config set-context --current --namespace'
  alias kcc='k config get-contexts'
  alias kd='k --force --grace-period=0 delete po'
  alias ka='k get all'
  alias kaa='k get all -A'
  alias kcf='k create -f'
  
  . <(kubectl completion bash)
  complete -F __start_kubectl k
  export do='-o yaml --dry-run=client'
  
  export KUBE_EDITOR=nano
}

When time is an important variable to consider, and you are like me --not a born in the terminal guy-- Nano is your editor, here the most recommended shortcuts to practice with.

Remember you can always use F1/^G

Useful Keyboard Shortcuts

Goto, Find, Replace

^_ (M-G) Go to line and column number
^W (F6) Search forward for a string or a regular expression
^\ (M-R) Replace a string or a regular expression

Copy and paste

^K (F9) Cut current line (or marked region) and store it in cutbuffer
^U (F10) Paste the contents of cutbuffer at current cursor position

Region

M-6 (M-^) Copy current line (or marked region) and store it in cutbuffer
M-A (^6) Mark text starting from the cursor position

Formating

M-} (Tab) Indent the current line (or marked lines)
M-{ (Sh-Tab) Unindent the current line (or marked lines)

Reading, Writing, Exiting

^X (F2) Close the current buffer / Exit from nano
^O (F3) Write the current buffer (or the marked region) to disk
^R (Ins) Insert another file into current buffer (or into new buffer)

I will just add to the connectivity commands recommended by aydarsh, the ones I think should help to create test pod on-demand or connect quickly to running containers

wget -O- http://10.44.0.1:80
curl http://10.44.0.1 80
nc -vz 10.44.0.1 80
k exec -it pod -- [command]
k run bash -it --image=bash --rm -- [command]