- Go 95.8%
- Makefile 4.2%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
| model | ||
| go.mod | ||
| go.sum | ||
| LICENSE | ||
| main.go | ||
| Makefile | ||
| Readme.md | ||
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
- Write the likec4 specification to a file with
k8s2likec4 spec > spec.c4 - Set your
KUBECONFIGand runk8s2likec4 > cluster.c4to write a likec4 deployment model. - Write a
view.c4file with the likec4 views that you need. An overview for a namespace can be generated withk8s2likec4 view -n {namespace} > view.c4. - Use
likec4 serveto open the diagrams in your browser. Update theview.c4file 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 > clustercommand to write the cluster model to a dedicated file, first. Then usek8s2likec4 namespace {namespace} > namespace.c4to write only a single namespace.
- 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:9980can be abreviated toexposes 80:9980because the host is shown as description of the ingress node and the service name is redunant with the target