Create likec4 deployment models from live kubernetes clusters
  • Go 95.8%
  • Makefile 4.2%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2025-10-13 16:55:42 +02:00
model embed default spec,views and calls 2025-10-02 17:59:37 +02:00
go.mod rename package 2025-10-02 11:13:57 +02:00
go.sum initial commit 2025-09-26 16:18:42 +02:00
LICENSE Create LICENSE 2025-10-13 16:55:42 +02:00
main.go embed default spec,views and calls 2025-10-02 17:59:37 +02:00
Makefile feat: add makefile 2025-10-13 14:19:11 +02:00
Readme.md feat: add makefile 2025-10-13 14:19:11 +02:00

k8s2likec4

A cli tool to create likec4 deployment models from live kubernetes clusters. It comes with an opinionated likec4 specification for Kubernetes objects and prints a deployment model to stdout by directly accessing a kubernetes cluster.

In a subsequent step, the model elements can then be visualized in likec4 views. The workflow can be used to document the state of any kubernetes deployment.

Modeling decisions

The primary relationship of kubernetes objects is modeled as a containment:

cluster {
  namespace {
    ingress
    service
    deployment|statefulset|daemonset {
      pod
    }
    pvc
  }
}

Note: Technically, deployments create a replicaset, but we leave it out of the model as it doesn't add a lot of value.

The pods exposed by Service objects as well as the services exposed by Ingress objects are modeled as a relationship with the port properties as part of the title. This makes the network aspects visible in views.

ingress -> service "Exposes {port(,...)}"
service -> deployment|statefulset|daemonset "Exposes {port(,...)}"
pod -> pvc "mounts /path/to/mount (RWO|RWX)"

Since NetworkPolicies describe pod to pod relations we manually preconfigure a list of calls that are made to the opencloud deployment:

deployment {
  extend prod {
    prod.deploy_opencloud_backend -[HTTP]-> prod.service_opencloud_api "Calls 9140,9216"
    prod.deploy_opencloud_backend -[GRPC]-> prod.service_opencloud_gateway "Calls 9142"
    prod.deploy_opencloud_backend -[GRPC]-> prod.service_opencloud_storage_system "Calls 9215"

    // Weboffice makes WOPI requests to our proxy
    prod.deploy_collabora_collabora_online -[HTTP]-> prod.service_opencloud_api "Calls 9200"

    // Opencloud makes call to Keycloak
    prod.service_opencloud_api -> prod.ingress_opencloud_keycloak_ingress "Calls 443"
  }
}

Note: This is a little brittle because we use the collabora deployment name that is used in the chart we use.

Workflow

You can see available Makefile commands and what they do by running:

make help
  1. Write the likec4 specification to a file with k8s2likec4 spec > spec.c4
  2. Set your KUBECONFIG and run k8s2likec4 > cluster.c4 to write a likec4 deployment model.
  3. Write a view.c4 file with the likec4 views that you need. An overview for a namespace can be generated with k8s2likec4 view -n {namespace} > view.c4 .
  4. Use likec4 serve to open the diagrams in your browser. Update the view.c4 file to contain views and diagrams you want to show.

Todo

  • Allow fetching only a single namespace. Use extend to reference the cluster. So we may also need a simple k8s2likec4 cluster > cluster command to write the cluster model to a dedicated file, first. Then use k8s2likec4 namespace {namespace} > namespace.c4 to write only a single namespace.
  1. how much of the example view can we reuse? Maybe Tag all objects from the same namespace with the same #namespace Tag and then create a view that contains all elements with that tag? Using an include with namespace-{name}.* does not seem to add sub children. element.** should do the trick!
  • rename to k8s2likec4
  • use service appProtocol as relationship kinds
  • Let weboffice directly talk to port 9300. It does not need to go through the proxy. We don't want to count and see it in the acces logs, or do we?
  • do not expose debug ports in a service. prometheus will connect to them directly, anyway
  • exposes weboffice.opencloud.test:80 → collabora-collabora-online:9980 can be abreviated to exposes 80:9980 because the host is shown as description of the ingress node and the service name is redunant with the target