Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

shortcut for typing kubectl --all-namespaces everytime

Tags:

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.

like image 452
Tinkaal Gogoi Avatar asked Sep 05 '18 07:09

Tinkaal Gogoi


People also ask

How do I list all namespaces in Kubernetes?

To list the existing namespaces in a cluster 'kubectl get namespace' command is used. After executing the command, the following output will be generated: Observe that the Kubernetes object starts with four initial namespaces: Default, kube-node-lease, kube-public, and kube-system.

What is the command to list all the pods from all namespaces in a Kubernetes cluster?

In this exercise you will use kubectl to fetch all of the Pods running in a cluster, and format the output to pull out the list of Containers for each.

Which command is used get all running pods of default namespace?

The most basic command for viewing Kubernetes objects via kubectl is get . If you run kubectl get <resource-name> you will get a listing of all resources in the current namespace.


2 Answers

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

kubectl get -A pod

(rejoice)

like image 120
Tracey Jaquith Avatar answered Oct 09 '22 18:10

Tracey Jaquith


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

like image 44
Const Avatar answered Oct 09 '22 18:10

Const