Kubegraph
Yet another kubernetes resource graph generator
π Table of Contents
π§ About
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.
π Getting Started
Fetch the dependencies and build with
make build
Prerequisites
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.
Installing
It can be installed using standard go install
go install ./...
Then, if you have GOPATH on your path, you can call kubepath
directly anywhere.
π§ Running the tests
WIP, there's no tests yet π
π Usage
kubegraph my-multidoc.yaml
or using the docker image
docker run --rm -it -v ${PWD}:/home/kubegraph wwmoraes/kubegraph:latest resources.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 drawed at all). A future
version will address this by using raster icons.
How to add support for a single/suite of custom resource definitions
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 update go.mod
and go.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 the internal/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's Create
function, on the call to statefulGraph.AddStyledNode
-
regenerate the icons embedded asset module with make icons
-
commit and profit :D
βοΈ Built Using
βοΈ Authors
π Acknowledgements
- Kubernetes sigs members for the excellent abstractions and interfaces available on Golang
- @damianopetrungaro for the honest reviews and patience