ahmetb/kubectl-tree

Support label selectors

Matt343 opened this issue · 2 comments

The tree command currently requires you to specify a single resource to use as the root. It would be helpful to instead be able to use a label selector (like kubectl get -l) and then build trees from each of the resources that match that selector.

This tool is currently a single-rooted tree, by design.

You can easily do

for res in $(kubectl get -l ...);  do
   kubectl tree "$res"
done

and make use of unix tool composability. :)

I don't want to open a can of worms like "what happens if one of the requests fail", "how do we render multiple trees" etc.

k9s supports this ("xray" command) if you are looking for an alternative.

My own workaround (bashrc):

kt(){
    for i in $(kubectl get -o jsonpath='{.metadata.name}{range .items[*]}{.metadata.name}{"\n"}{end}' "$@"); do
        kubectl tree "$1" "$i"
    done
}

This allows kt deploy, kt deploy webserver, kt deploy -l app=webserver, etc.