28

Is there any alias we can make for all-namespace as kubectl don't recognise the command kubectl --all-namespaces or any kind of shortcut to minimize the typing of the whole command.

Tinkaal Gogoi
  • 4,344
  • 4
  • 27
  • 36

2 Answers2

68

New in kubectl v1.14, you can use -A instead of --all-namespaces, eg:

kubectl get -A pod

(rejoice)

Reference: https://kubernetes.io/docs/reference/kubectl/cheatsheet/#a-note-on-all-namespaces

Apiwat Chantawibul
  • 1,271
  • 1
  • 10
  • 20
Tracey Jaquith
  • 681
  • 1
  • 5
  • 2
20

Is there any alias we can make for all-namespace

Based on this excellent SO answer you can create alias that inserts arguments between prefix and suffix like so:

alias kca='f(){ kubectl "$@" --all-namespaces -o wide;  unset -f f; }; f'

and then use it regularly like so:

kca get nodes
kca get pods
kca get svc,sts,deploy,pvc,pv

etc..

Note: There is -o wide added for fun as well to get more detailed info about resources not normally namespaced like nodes and pv...

Const
  • 6,237
  • 3
  • 22
  • 27
  • 1
    Most of the other answers to that question recommended simply writing a shell function and that seems like it'd be more appropriate here. – David Maze Sep 05 '18 at 10:29
  • 1
    Sure, in referenced SO answer it is discussed at length and I wholeheartedly suggest a read on that! This is simply an attempt to answer a question "is there any alias we can make"? Btw, this uses function as well, albeit a bit different :) – Const Sep 05 '18 at 10:37