# Kubectl tips and tricks

**URL:** <https://discuss.kubernetes.io/t/kubectl-tips-and-tricks/192>\
**Category:** General Discussions\
**Created:** [May 11, 2018, 9:58pm UTC](https://discuss.kubernetes.io/t/kubectl-tips-and-tricks/192 "2018-05-11T21:58:45Z")\
**Posts on this page:** 1\
**Showing post:** 84

<div class="post-metadata">

**Author:** ![amacheco](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.kubernetes.io/amacheco/32/5101_2.png) [@amacheco](https://discuss.kubernetes.io/u/amacheco)\
**Post date:** [June 20, 2020, 3:34am UTC](https://discuss.kubernetes.io/t/kubectl-tips-and-tricks/192/84 "2020-06-20T03:34:06Z")

</div>

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.

```auto
{
  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]`

---

_[View the full topic](https://discuss.kubernetes.io/t/kubectl-tips-and-tricks/192)._
