k8s-dot-graph

0.1.1 • Public • Published

node-k8s-dot-graph

NPM

node.js library to create a dot graph (e.g. graphviz) from kubernetes objects. This lets you create a graph visualization of your kubernetes cluster.

Inputs are the kubernetes object lists from the k8s api endpoints for NodeList, PodList, ServiceList, and IngressList and output is a string in dot format representing the kubernetes cluster.

Example Code

import kdg from 'k8s-dot-graph'
 
async function main() {
  const nodeList    = await getNodeList()
  const podList     = await getPodList()
  const ingressList = await getIngressList()
  const serviceList = await getServiceList()
 
  const dotGraphString = kdg.makeDotGraph({nodeList, serviceList, podList, ingressList})
}
 

Options

makeDotGraph() accepts the following dot format options with defaults shown:

 
kdg.makeDotGraph({
  nodeList,
  serviceList,
  podList,
  ingressList,
  splines      : 'ortho',
  sep          : '6.2',
  ranksep      : '2.0 equally',
  internetShape: 'circle',
})

Installation

npm install k8s-dot-graph

Example Output

This is an example of a small 2-node, 3-pod cluster. These get much larger.

digraph {
sep=6.2;
ranksep="2.0 equally";
splines="ortho";
"svcs:app1" [label="service: app1"][shape=diamond];
"svcs:auth" [label="service: auth"][shape=diamond];
"svcs:redis-master" [label="service: redis-master"][shape=diamond];
"pods:app1-3746604072-3jfn8" [label="app1-3746604072-3jfn8"][shape=oval];
"pods:auth-1124301931-8h7fp" [label="auth-1124301931-8h7fp"][shape=oval];
"pods:redis-master-853269215-glqjs" [label="redis-master-853269215-glqjs"][shape=oval];
"ings:svc" [label="ingress: svc"][shape=invtriangle];
"internet" [label="internet"][shape=circle];subgraph "cluster-gke-testcluster-pool-3-0aa49f08-p92k" { label="node: gke-testcluster-pool-3-0aa49f08-p92k";
"pods:auth-1124301931-8h7fp";
"pods:redis-master-853269215-glqjs";
}
 
subgraph "cluster-gke-testcluster-pool-3-cc049887-zsmc" { label="node: gke-testcluster-pool-3-cc049887-zsmc";
"pods:app1-3746604072-3jfn8";
}
"internet" -> "ings:svc";
"internet" -> "svcs:app1";
"ings:svc" -> "svcs:auth";
"svcs:app1" -> "pods:app1-3746604072-3jfn8";
"svcs:auth" -> "pods:auth-1124301931-8h7fp";
"svcs:redis-master" -> "pods:redis-master-853269215-glqjs";
}

Example Visualized

Example output

Contributions

Issues/PRs are welcome.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.1.1
    0
    • latest

Version History

Package Sidebar

Install

npm i k8s-dot-graph

Weekly Downloads

0

Version

0.1.1

License

MIT

Last publish

Collaborators

  • chrishiestand