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.
2 Answers
New in kubectl v1.14, you can use -A
instead of --all-namespaces
, eg:
kubectl get -A pod
(rejoice)
-
2I vote to make THIS the accepted answer! Please change it! It has double as many upvotes. Feb 13, 2021 at 2:31
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
...
-
1Most of the other answers to that question recommended simply writing a shell function and that seems like it'd be more appropriate here. Sep 5, 2018 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 :)– ConstSep 5, 2018 at 10:37
alias ksa='kubectl get all --all-namespaces'
to make it shorter.get all
is really what you want kubectl to display (some resources are omitted that way, just a friendly reminder).