MCPcopy
hub / github.com/ahmetb/kubectl-tree

github.com/ahmetb/kubectl-tree @v0.6.0 sqlite

repository ↗ · DeepWiki ↗ · release v0.6.0 ↗
37 symbols 104 edges 9 files 10 documented · 27%
README

kubectl tree logo

kubectl tree

A kubectl plugin to explore ownership relationships between Kubernetes objects through ownersReferences on the objects.

The kubectl lineage plugin is very similar to kubectl tree, but it understands logical relationships between some API objects without needing ownerReferences.

Installation

Use krew plugin manager to install:

kubectl krew install tree
kubectl tree --help

Demo

Example (Deployment):

example Kubernetes deployment object hierarchy

Example (Knative Service):

example Kubernetes object hierarchy with Knative Service

Example (Agones Fleet):

example Kubernetes object hierarchy with Agones Fleet

Flags

By default, the plugin searches only namespaced objects in the same namespace as the specified object.

  • -A, --all-namespaces: Search namespaced and non-namespaced objects in all namespaces.

  • -n, --namespace: Namespace scope for the CLI request.

  • -c, --color: Control color output. Supported values are always, never, and auto (default).

  • -l, --selector: Selector (label query) to filter on. Supports equality (=, ==, !=), set-based (in, notin), and existence operators. Examples:

  • -l key1=value1,key2=value2 (equality)
  • -l "env in (prod,staging)" (set-based)
  • -l "tier=frontend,env!=test" (mixed)

This helps reduce workload and data volume when working with large clusters.

  • --condition-types: Comma-separated list of condition types to check. Default: Ready. Example: Ready,Processed,Scheduled.

  • --api-groups: Comma-separated list of API groups to include in the query. When not set, all API groups are included. Supports globs. Example: --api-groups=core,*cluster.x-k8s.io,!addons.*,*.cert-manager.io.

  • --resources: Comma-separated list of resource types to include in the query. When not set, all resources are included. Supports globs. Example: --resources=deployments,rs,pods.

Resource filters accept kind, singular, plural, and short names. For example, ReplicaSets, replicasets, replicaset, and rs all match the same resource type.

Using --resources and --api-groups to define what APIs and resources are included or excluded while building the tree can significantly reduce workload and data usage in large clusters. If an intermediate owner resource is filtered out, traversal stops at that point and child resources below it will be missing, even if the leaf resource or API would otherwise match. For example, using --resources=deployments,pods will return nothing because replicasets are not included and pods are not directly owned by deployments.

kubectl tree --api-groups '*.custom.api,*cluster.x-k8s.io' --resources '!customresource' cluster my-cluster

Author

Ahmet Alp Balkan @ahmetb.

Special acknowledgement: This tool is heavily inspired by @nimakaviani's knative-inspect as it's a generalized version of it.

License

Apache 2.0. See LICENSE.


This is not an official Google project.

Core symbols most depended-on inside this repo

GroupVersionResource
called by 9
cmd/kubectl-tree/apis.go
extractStatus
called by 2
cmd/kubectl-tree/status.go
matchAny
called by 2
cmd/kubectl-tree/apis.go
matchGroups
called by 2
cmd/kubectl-tree/apis.go
matchResources
called by 2
cmd/kubectl-tree/apis.go
getNamespace
called by 2
cmd/kubectl-tree/namespace.go
getAllResources
called by 1
cmd/kubectl-tree/query.go
queryAPI
called by 1
cmd/kubectl-tree/query.go

Shape

Function 22
Method 8
TypeAlias 4
Struct 3

Languages

Go100%

Modules by API surface

cmd/kubectl-tree/apis.go13 symbols
cmd/kubectl-tree/relationship.go8 symbols
cmd/kubectl-tree/rootcmd.go4 symbols
cmd/kubectl-tree/tree.go3 symbols
cmd/kubectl-tree/status.go3 symbols
cmd/kubectl-tree/query.go2 symbols
cmd/kubectl-tree/apis_test.go2 symbols
cmd/kubectl-tree/status_test.go1 symbols
cmd/kubectl-tree/namespace.go1 symbols

Dependencies from manifests, versioned

github.com/Azure/go-ansitermv0.0.0-2023012417243 · 1×
github.com/blang/semver/v4v4.0.0 · 1×
github.com/fxamacker/cbor/v2v2.9.0 · 1×
github.com/go-errors/errorsv1.4.2 · 1×
github.com/go-logr/logrv1.4.3 · 1×
github.com/go-openapi/jsonpointerv0.21.0 · 1×
github.com/go-openapi/jsonreferencev0.20.2 · 1×
github.com/go-openapi/swagv0.23.0 · 1×
github.com/google/btreev1.1.3 · 1×

For agents

$ claude mcp add kubectl-tree \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact