kubectl-graph
A kubectl plugin to visualize Kubernetes resources and relationships.
Quickstart
This quickstart guide uses homebrew and docker on macOS
in the usage examples.
Prerequisites
This plugin requires Graphviz or Neo4j to visualize the dependency graph.
Graphviz
To render the default output format, you'll need to install the dot
command line tool first:
brew install graphviz
Neo4j
To connect to a Neo4j database, you'll need to install the cypher-shell
command line tool first:
brew install cypher-shell
Installation
This kubectl
plugin is distributed via krew.
To install it, run the following command:
before kubectl 1.19
kubectl-krew install graph
kubectl from 1.19
kubectl krew install graph
Usage
Graphviz
This kubectl graph
command will fetch all running Pods in the namespace kube-system
and outputs a graph in the DOT format.
We could also pipe the output directly to the dot
command, which can create an image file:
kubectl graph pods --field-selector status.phase=Running -n kube-system | dot -T svg -o pods.svg
Now we'll have an image file in the current working directory. This SVG file can then be viewed in any web browser:
open pods.svg
If you're not happy with the SVG output format, please take a look at the offical Graphviz documentation.
Neo4j
Before you can import all your Kubernetes resources, we need to create a Neo4j database.
I prefer to use the Neo4j Desktop.app
installed via brew cask install neo4j
, but you can also start a Neo4j instance via docker:
docker run --rm -p 7474:7474 -p 7687:7687 -e NEO4J_AUTH=none neo4j
After the container is up and running you can start to import all your Kubernetes resources into Neo4j:
kubectl graph all -n kube-system -o cypher | cypher-shell
When the import is complete, you can open the Neo4j Browser interface at http://localhost:7474/.
Examples
Grafana Loki
Loki is a horizontally-scalable, highly-available, multi-tenant log aggregation system inspired by Prometheus.
kubectl graph all -n loki -o cypher | cypher-shell -u neo4j -p secret
Development
go run ./cmd/kubectl-graph/main.go all -n <namspace> | dot -T png -o all.png
Status
This kubectl
plugin is under active development.
License
This project is licensed under the Apache License 2.0, see LICENSE for more information.