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.

4
  • 1
    Dont 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 5, 2018 at 7:38
  • 1
    @Tinkal Gogoi, how about creating an alias in dot profile and giving it a try once? Sep 5, 2018 at 7:59
  • 2
    If 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 5, 2018 at 8:00
  • This answer is depreciated and not current anymore. Feb 13, 2021 at 2:32

2 Answers 2

65

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

kubectl get -A pod

(rejoice)

1
  • 2
    I vote to make THIS the accepted answer! Please change it! It has double as many upvotes. Feb 13, 2021 at 2:31
17

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...

2
  • 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 5, 2018 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 5, 2018 at 10:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.