Executes kubectl get ...
command for multiple namespaces to get any resource you want.
- kubens (
kubectl-mo
uses information stored bykubens
to figure out the last used namespace)
For example, let's say your current namespace is kube-system
:
$ kubectl config view --minify -o jsonpath='{..namespace}'
kube-system
You change the namespace to default
using kubens
:
$ kubens default
Context "k3d-dynamic-corefile" modified.
Active namespace is "default".
Now, if you want to get any resource from the current and the last namespace, you can use kubectl-mo
like this:
$ kubectl mo get configmaps
executing command /home/suraj/bin/kubectl -n default get configmaps
NAME DATA AGE
kube-root-ca.crt 1 33d
executing command /home/suraj/bin/kubectl -n kube-system get configmaps
NAME DATA AGE
extension-apiserver-authentication 6 33d
cluster-dns 2 33d
local-path-config 4 33d
chart-content-traefik 0 33d
chart-values-traefik 1 33d
chart-content-traefik-crd 0 33d
chart-values-traefik-crd 0 33d
kube-root-ca.crt 1 33d
coredns 2 33d
$ kubectl mo get pods
executing command /home/suraj/bin/kubectl -n default get po
NAME READY STATUS RESTARTS AGE
nginx 1/1 Running 14 (53m ago) 11d
executing command /home/suraj/bin/kubectl -n kube-system get po
NAME READY STATUS RESTARTS AGE
helm-install-traefik-crd-vplbc 0/1 Completed 0 33d
helm-install-traefik-q26gv 0/1 Completed 1 33d
local-path-provisioner-7b7dc8d6f5-q8k6x 1/1 Running 51 (53m ago) 33d
coredns-b96499967-tmswr 1/1 Running 51 (53m ago) 33d
svclb-traefik-98312b71-66crq 2/2 Running 121 (53m ago) 33d
traefik-7cd4fcff68-dt82t 1/1 Running 51 (53m ago) 33d
metrics-server-668d979685-tbblc 1/1 Running 51 (53m ago) 33d
In general, you can use:
$ kubectl mo get <any-resource> <flags>
To execute any kubectl get ...
command with flags in your current and last namespace.
- none (you can use this feature without
kubens
)
Instead of running kubectl get ...
in the current and the last namespace, you want to run kubectl get ...
in arbitrary multiple namespaces, you can do:
$ kubectl mo get configmaps -ns=kube-public,kube-node-lease
executing command /home/suraj/bin/kubectl -n kube-public get configmaps
NAME DATA AGE
kube-root-ca.crt 1 33d
executing command /home/suraj/bin/kubectl -n kube-node-lease get configmaps
NAME DATA AGE
kube-root-ca.crt 1 33d
In general,
$ kubectl mo get <any-resource> <flags> -ns=ns1,ns2...
If you add -ns
flag kubectl-mo
doesn't execute kubectl get ...
in the current and the last namespace.
kubectl-mo
uses thekubectl
binary available on the user's machine. This is intentional. We wantkubectl-mo
to be compatible with different versions ofkubectl
.
- When you are working with kubernetes, you often want to see resources in multiple namespaces but
kubectl
doesn't give you that functionality. To be specific, you often want one of the following:- Look for resources in your current and the last used namespace to avoid constantly switching namespaces
- Look for resources in your current and last N namespaces
- Look for resources in arbitrary multiple namespaces
- There have been issues filed around this but there doesn't seem to be any progress on solving this problem in the upstream
kubectl
code: - There have been attempts to solve this problem using a plugin:
- kubernetes/kubernetes#52326 (comment)
- Above implementation solves 3 but doesn't solve 1 and 2
kubectl-mo
solves 1 and 3 but doesn't solve 2 yet.
- If you have too many resources in your namespaces, using
kubectl-mo get
might take time to execute because the underlyingkubectl get ...
takes time to execute.
We'd love to know what you think about the plugin. Feel free to create an issue to give us feedback, suggestions, file bugs or ask for new features.
- It would be nice to have a way to let
kubectl-mo
figure out the last 5 namespaces that the user used. This includes the namespaces user switched to (using saykubens
) and also the namespaces user used in theirkubectl
command using--namespace
or-n
flag.kubectl-mo
can then automatically query for resources in those last 5 namespaces. - It would be nice if the user can specify namespaces once and
kubectl-mo
uses the namespaces in subsequent commands. For example:
$ kubectl mo get po -ns=default,kube-system
# kubectl mo saves `default` and `kube-system` namespaces
$ kubectl-mo get po # no need to specify `-ns` again
$ kubectl mo get po -ns=dev,prod
# kubectl-mo overwrites last saved namespaces i.e., `default` and `kube-system` with `dev` and `prod`
$ kubectl mo get po # no need to specify `-ns` again
Note: Future scope will be worked upon based on user interest