Search This Blog

Monday 13 January 2020

kubectl tree - A kubectl plugin to explore ownership relationships between Kubernetes objects through ownersReferences

A kubectl plugin to explore ownership relationships between Kubernetes objects through ownersReferences on them. To get started and install the plugin visit this page.

https://github.com/ahmetb/kubectl-tree

Install Steps

Install as follows

1. Create a script as follows

install-krew.sh

(
  set -x; cd "$(mktemp -d)" &&
  curl -fsSLO "https://github.com/kubernetes-sigs/krew/releases/download/v0.3.3/krew.{tar.gz,yaml}" &&
  tar zxvf krew.tar.gz &&
  KREW=./krew-"$(uname | tr '[:upper:]' '[:lower:]')_amd64" &&
  "$KREW" install --manifest=krew.yaml --archive=krew.tar.gz &&
  "$KREW" update
)

2. Install as follows

papicella@papicella:~/pivotal/software/krew$ ./install-krew.sh
+++ mktemp -d
++ cd /var/folders/mb/93td1r4s7mz3ptq6cmpdvc6m0000gp/T/tmp.kliHlfYB
++ curl -fsSLO 'https://github.com/kubernetes-sigs/krew/releases/download/v0.3.3/krew.{tar.gz,yaml}'
++ tar zxvf krew.tar.gz
x ./krew-darwin_amd64
x ./krew-linux_amd64
x ./krew-linux_arm
x ./krew-windows_amd64.exe
x ./LICENSE
+++ uname
+++ tr '[:upper:]' '[:lower:]'
++ KREW=./krew-darwin_amd64
++ ./krew-darwin_amd64 install --manifest=krew.yaml --archive=krew.tar.gz
Installing plugin: krew
Installed plugin: krew

...

3. On a Mac add the following to your PATH and source your profile file or start a new shell

export PATH="${KREW_ROOT:-$HOME/.krew}/bin:$PATH"

4. Check plugin is installed

$ kubectl plugin list
The following compatible plugins are available:

/Users/papicella/.krew/bin/kubectl-krew
/Users/papicella/.krew/bin/kubectl-tree

Can also use this:

$ kubectl tree --help
Show sub-resources of the Kubernetes object

Usage:
  kubectl tree KIND NAME [flags]

Examples:
  kubectl tree deployment my-app
  kubectl tree kservice.v1.serving.knative.dev my-app

6. Ok now it's installed let's see what it shows / displays information about k8s objects and relationships on my cluster which has riff and knative installed

$ kubectl tree deployment --namespace=knative-serving networking-istio
NAMESPACE        NAME                                       READY  REASON  AGE
knative-serving  Deployment/networking-istio                -              8d
knative-serving  └─ReplicaSet/networking-istio-7fcd97cbf7   -              8d
knative-serving    └─Pod/networking-istio-7fcd97cbf7-z4dc9  True           8d

$ kubectl tree deployment --namespace=riff-system riff-build-controller-manager
NAMESPACE    NAME                                                    READY  REASON  AGE
riff-system  Deployment/riff-build-controller-manager                -              8d
riff-system  └─ReplicaSet/riff-build-controller-manager-5d484d5fc4   -              8d
riff-system    └─Pod/riff-build-controller-manager-5d484d5fc4-7rhbr  True           8d


More Information

GitHub Tree Plugin
https://github.com/ahmetb/kubectl-tree

No comments: