Yet another kubernetes resource graph generator
Kubegraph is a CLI tool that parses kubernetes resources and generates a graph with the relations between those. The graph is done using Graphviz, and can be further customized after generation.
Fetch the dependencies and build with
make build
Kubegraph is done using Golang 1.15, using a pure Go graphviz implementation to generate the graph.
Everything is set as a direct dependency, and go mod vendor
will install for you.
It can be installed using standard go install
go install ./...
Then, if you have GOPATH on your path, you can call kubepath
directly anywhere.
WIP, there's no tests yet 😞
kubegraph my-multidoc.yaml
or using the docker image
docker run --rm -it -v ${PWD}:/home/kubegraph wwmoraes/kubegraph:latest my-multidoc.yaml
On this example, a my-multidoc.dot
file will be generated, alongside with an
icons
folder used by the graph. You can convert it to an image using dot
, e.g.
dot -Tsvg -o my-multidoc.svg my-multidoc.dot
If your graphviz installation has been compiled with pango, cairo and rsvg, you'll also be able to generate static formats as png or jpeg. Do note that currently kubegraph uses svg icons, and cairo mess up when generating raster images with those (namely they'll either look blurred or won't be drawn at all). A future version will address this by using raster icons.
First, import the scheme and add it to client-go's scheme on internal/loader/getDecoder.go@init
:
import (
"k8s.io/client-go/kubernetes/scheme"
// import the target scheme
myAwesomeScheme "githost.com/owner/repository/pkg/client/clientset/scheme"
)
func init() {
// add the scheme to client-go's scheme
_ = myAwesomeScheme.AddToScheme(scheme.Scheme)
}
then:
-
vendor it with
go mod vendor
to updatego.mod
andgo.sum
-
add adapters for the kinds on that scheme at
internal/adapters/<api-group>/<api-version>
. You can copy from an existing one, or use theinternal/adapters/dummy/v1/dummy.go
as a guide. -
import your API versions on the group level (check
internal/adapters/dummy/dummy.go
) -
import the group on the top level on
internal/adapters/adapters.go
-
[optional, recommended] add a SVG icon for the new kinds on
icons/
and set it on your adapter'sCreate
function, on the call tostatefulGraph.AddStyledNode
-
regenerate the icons embedded asset module with
make icons
-
commit and profit :D
- Golang - Base language
- wwmoraes/dot - plain Go Graphviz package
- k8s.io/client-go - Kubernetes Go client
- kubernetes/community - amazing icons
- spf13/cobra - CLI framework
- @wwmoraes - Idea & Initial work
- Kubernetes sigs members for the excellent abstractions and interfaces available on Golang
- @damianopetrungaro for the honest reviews and patience