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.
Asked
Active
Viewed 8,701 times
28

Tinkaal Gogoi
- 4,344
- 4
- 27
- 36
-
1Dont think there is a way to create alias that way. I use `alias ksa='kubectl get all --all-namespaces'` to make it shorter. – chinmay Sep 05 '18 at 07:38
-
1@Tinkal Gogoi, how about creating an alias in dot profile and giving it a try once? – RavinderSingh13 Sep 05 '18 at 07:59
-
2If you decide to go this way, make sure that `get all` is really what you want kubectl to display (some resources are omitted that way, just a friendly reminder). – Const Sep 05 '18 at 08:00
-
This answer is depreciated and not current anymore. – Markus Bawidamann Feb 13 '21 at 02:32
2 Answers
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
-
2I vote to make THIS the accepted answer! Please change it! It has double as many upvotes. – Markus Bawidamann Feb 13 '21 at 02:31
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
-
1Most 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
-
1Sure, 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