tree visualization of Kubernetes objects

2 min read | by Jordi Prats

Some kubernetes objects creates and manages other kubernetes objects in order to provide it's functionality. For example, the Deployment object creates a ReplicaSet that in turn creates the desired Pod objects. We can always track down this relationship using kubectl describe but using the tree krew plugin we can see the relationship in a visual way. We can install it like so:

$ kubectl krew install tree

Once installed we can see the relationships of any objects by name, for example:

$ kubectl tree deploy pet2cattle
NAMESPACE    NAME                                 READY  REASON  AGE  
kube-system  Deployment/pet2cattle                -              173d 
kube-system  ├─ReplicaSet/pet2cattle-6459fd5cfd   -              7d14h
kube-system  ├─ReplicaSet/pet2cattle-6958646f9    -              9d   
kube-system  ├─ReplicaSet/pet2cattle-69f9f4c65d   -              12d  
kube-system  ├─ReplicaSet/pet2cattle-6f6b9648ff   -              18d  
kube-system  ├─ReplicaSet/pet2cattle-786fd7c9d6   -              11d  
kube-system  ├─ReplicaSet/pet2cattle-798578ccc8   -              4d1h 
kube-system   └─Pod/pet2cattle-798578ccc8-49pnx  True           4d1h 
kube-system  ├─ReplicaSet/pet2cattle-7dbbd9bf7f   -              11d  
kube-system  ├─ReplicaSet/pet2cattle-7f9895c54f   -              18d  
kube-system  ├─ReplicaSet/pet2cattle-946bcdb57    -              7d14h
kube-system  ├─ReplicaSet/pet2cattle-bf7575fbd    -              13d  
kube-system  └─ReplicaSet/pet2cattle-f94d49cb4    -              18d  

Here we can see that only one of the ReplicaSet has a pod, that's because all the other are revisions:

$ kubectl describe ReplicaSet/pet2cattle-798578ccc8 | grep revision
                deployment.kubernetes.io/revision: 124
$ kubectl describe ReplicaSet/pet2cattle-946bcdb57 | grep revision
                deployment.kubernetes.io/revision: 123
$ kubectl describe ReplicaSet/pet2cattle-6459fd5cfd | grep revision
                deployment.kubernetes.io/revision: 122

The old ReplicaSet are scaled down to 0 pods:

$ kubectl describe ReplicaSet/pet2cattle-f94d49cb4 | grep ^Repli
Replicas:       0 current / 0 desired

So just the active ReplicaSet has an active Pod on this moment.

We can also visualize other objects such as Service:

$ kubectl tree svc pet2cattle
NAMESPACE    NAME                              READY  REASON  AGE 
kube-system  Service/pet2cattle                -              173d
kube-system  └─EndpointSlice/pet2cattle-hzjn7  -              173d

Or an Ingress, on this example we can see the Certificate objects that it's using:

$ kubectl tree ingresses.v1.networking.k8s.io pet2cattle-https
NAMESPACE    NAME                                  READY  REASON  AGE 
kube-system  Ingress/pet2cattle-https              -              173d
kube-system  └─Certificate/k3s-p2c                 True   Ready   173d
kube-system    ├─CertificateRequest/k3s-p2c-7zl4g  True   Issued  116d
kube-system     └─Order/k3s-p2c-7zl4g-3064267605  -              116d
kube-system    ├─CertificateRequest/k3s-p2c-98vv5  True   Issued  37h 
kube-system     └─Order/k3s-p2c-98vv5-3758948428  -              37h 
kube-system    ├─CertificateRequest/k3s-p2c-flsnr  True   Issued  173d
kube-system     └─Order/k3s-p2c-flsnr-424107949   -              173d
kube-system    └─CertificateRequest/k3s-p2c-wwq4n  True   Issued  63d 
kube-system      └─Order/k3s-p2c-wwq4n-3758948428  -              63d 

Posted on 14/06/2021