ahmetb / kubectl-tree

kubectl plugin to browse Kubernetes object hierarchies as a tree 🎄 (star the repo if you are using)
Apache License 2.0
2.92k stars 118 forks source link

Support label selectors #21

Closed Matt343 closed 4 years ago

Matt343 commented 4 years ago

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.

ahmetb commented 4 years ago

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.

remram44 commented 2 years ago

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.