https://github.com/steveteuber/kubectl-graph
A kubectl plugin to visualize Kubernetes resources and relationships.
https://github.com/steveteuber/kubectl-graph
Last synced: 7 days ago
JSON representation
A kubectl plugin to visualize Kubernetes resources and relationships.
- Host: GitHub
- URL: https://github.com/steveteuber/kubectl-graph
- Owner: steveteuber
- License: apache-2.0
- Created: 2020-02-15T13:00:44.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2025-03-24T17:12:14.000Z (24 days ago)
- Last Synced: 2025-04-03T22:41:36.264Z (14 days ago)
- Language: Go
- Size: 1.1 MB
- Stars: 628
- Watchers: 7
- Forks: 32
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ccamel - steveteuber/kubectl-graph - A kubectl plugin to visualize Kubernetes resources and relationships. (Go)
- awesomeness - kubectl-graph - A kubectl plugin to visualize Kubernetes resources and relationships. (Containers / Kubernetes)
- awesome-starred - steveteuber/kubectl-graph - A kubectl plugin to visualize Kubernetes resources and relationships. (others)
- awesome-kubectl-plugins - kubectl-graph - graph)](https://github.com/steveteuber/kubectl-graph/stargazers) | (kubectl Plugins / Installing plugins via awesome-kubectl-plugins)
README
# kubectl-graph
[](https://github.com/steveteuber/kubectl-graph/blob/main/LICENSE)
[](https://goreportcard.com/report/github.com/steveteuber/kubectl-graph)
[](https://github.com/steveteuber/kubectl-graph/actions/workflows/ci.yml?query=branch:main)
[](https://github.com/steveteuber/kubectl-graph/issues)
[](https://github.com/steveteuber/kubectl-graph/blob/main/go.mod#L3)
[](https://github.com/steveteuber/kubectl-graph/releases/latest)A kubectl plugin to visualize Kubernetes resources and relationships.
## Prerequisites
This plugin requires [Graphviz](https://graphviz.org), [Neo4j](https://neo4j.com) *or* [ArangoDB](https://www.arangodb.com) to visualize the dependency graph.
Graphviz
The *default* output format requires `dot` to convert the output into a useful format.
```
brew install graphviz
```Neo4j
The *CQL* output format requires `cypher-shell` to connect to a Neo4j database.
```
brew install cypher-shell
```ArangoDB
The *AQL* output format requires `curl` and `jq` to send API requests to an ArangoDB server.
```
brew install curl jq
```Do you miss something? Please open an issue or create a pull request.
## Installation
This `kubectl` plugin is distributed via [krew](https://krew.sigs.k8s.io). To install it, run the following command:
```
kubectl krew install graph
```## Usage
In general, this plugin is working like `kubectl get` but it tries to resolve relationships between the Kubernetes
resources before it prints a graph in `AQL`, `CQL` *or* `DOT` format. By default, the plugin will use `DOT` as output format.```
kubectl graph [(-o|--output=)aql|arangodb|cql|cypher|dot|graphviz|mermaid] (TYPE[.VERSION][.GROUP] ...) [flags]
```## Quickstart
This quickstart guide uses macOS. It's possible that the commands can differ on other operating systems.
### Graphviz

When you have installed the `dot` command line tool, then you can start to fetch all running Pods in the
`kube-system` namespace and pipe the output directly to the `dot` command.```
kubectl graph pods --field-selector status.phase=Running -n kube-system | dot -T svg -o pods.svg
```Now you will have a `pods.svg` file in the current working directory, which can be viewed with any web browser:
```
open pods.svg
```If you're not happy with SVG as output format, please take a look at the offical [documentation](https://graphviz.org/doc/info/output.html).
### Neo4j

Before you can import all your Kubernetes resources, you will need to create a Neo4j database.\
This can be done in multiple ways and is based on your preference.Docker
[Docker](https://docs.docker.com/get-started/) is the easiest way to get started with a Neo4j server and an empty database.
```
docker run --rm -p 7474:7474 -p 7687:7687 -e NEO4J_AUTH=neo4j/secret neo4j
```When the container is up and running then you can open the Neo4j Browser interface at http://localhost:7474/.
Neo4j Desktop
The [Neo4j Desktop](https://neo4j.com/developer/neo4j-desktop/) application lets you easily create any number of local databases.
```
brew install --cask neo4j
```After installation, open the `Neo4j Desktop.app` and do the following steps:
1. Create a new project and give it a name.
2. Create a new local DBMS with a name like `quickstart` and password `secret`.
3. Click Start and enter the password.
4. When the database is up and running then you can click Open to open the Neo4j Browser interface.
When you have opened the Neo4j Browser interface, then you can start to fetch all resources in the
`kube-system` namespace and pipe the output directly to the `cypher-shell` command.```
kubectl graph all -n kube-system -o cypher | cypher-shell -u neo4j -p secret
```Finally, within the Neo4j Browser interface you can enter the following queries in the command line:
```
MATCH (n) RETURN n // Render all nodes as a visual graph
MATCH (n) DETACH DELETE n // Delete all nodes and relationships
```For more information about the Cypher query language, please take a look at the offical [documentation](https://neo4j.com/docs/cypher-manual/current/clauses/).
### ArangoDB

Before you can import all your Kubernetes resources, you will need to create an ArangoDB database.\
This can be done in multiple ways and is based on your preference.Docker
[Docker](https://docs.docker.com/get-started/) is the easiest way to get started with an ArangoDB server and an empty database.
```
docker run --rm -p 8529:8529 -e ARANGO_NO_AUTH=1 arangodb
```When the container is up and running then you can open the ArangoDB Browser interface at http://localhost:8529/.
If you start with an empty database you need to create two collections one for resources and one for relationships.
```
curl http://localhost:8529/_api/collection -d '{"type": 2, "name": "resources"}'
curl http://localhost:8529/_api/collection -d '{"type": 3, "name": "relationships"}'
```After that you also need to create a graph which requires the name and a definition of its edges.
```
curl http://localhost:8529/_api/gharial -d @- < | dot -T png -o all.png
```## License
This project is licensed under the Apache License 2.0, see [LICENSE](LICENSE) for more information.