diff --git a/README.md b/README.md index 7a49aff..ba1c4ce 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ **Diagram as Code**. -Diagrams lets you draw the cloud system architecture **in Python code**. It was born for **prototyping** a new system architecture design without any design tools. You can also describe or visualize the existing system architecture as well. Diagrams currently supports three major cloud providers: `AWS`, `Azure`, `GCP`. +Diagrams lets you draw the cloud system architecture **in Python code**. It was born for **prototyping** a new system architecture design without any design tools. You can also describe or visualize the existing system architecture as well. Diagrams currently supports four major providers: `AWS`, `Azure`, `GCP` and `Kubernetes`. **Diagram as Code** also allows you to **tracking** the architecture diagram changes on any **version control** system. @@ -31,9 +31,11 @@ You can start with [quick start](https://diagrams.mingrammer.com/docs/installati ## Examples -| Grouped Workers | Clustered Web Services | Event Processing | -| ------------------------------------------------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ | -| ![grouped workers](https://diagrams.mingrammer.com/img/grouped_workers_diagram.png) | ![clustered web services](https://diagrams.mingrammer.com/img/clustered_web_services_diagram.png) | ![event processing](https://diagrams.mingrammer.com/img/event_processing_diagram.png) | +| Grouped Workers | Clustered Web Services | +| ------------------------------------------------------------ | ------------------------------------------------------------ | +| ![grouped workers](https://diagrams.mingrammer.com/img/grouped_workers_diagram.png) | ![clustered web services](https://diagrams.mingrammer.com/img/clustered_web_services_diagram.png) | +| **Event Processing** | **Stateful Architecture** | +| ![event processing](https://diagrams.mingrammer.com/img/event_processing_diagram.png) | ![stateful architecture](https://diagrams.mingrammer.com/img/stateful_architecture_diagram.png) | You can find all the examples on the [examples](https://diagrams.mingrammer.com/docs/examples) page. diff --git a/autogen.sh b/autogen.sh index c5859de..5d26d18 100755 --- a/autogen.sh +++ b/autogen.sh @@ -2,7 +2,7 @@ app_root_dir="diagrams" # NOTE: azure icon set is not latest version -providers=("aws" "azure" "gcp") +providers=("aws" "azure" "gcp" "k8s") if ! [ -x "$(command -v round)" ]; then echo 'round is not installed' diff --git a/config.py b/config.py index f19bec8..dc0cca6 100644 --- a/config.py +++ b/config.py @@ -10,7 +10,7 @@ DIR_APP_ROOT = "diagrams" DIR_RESOURCE = "resources" DIR_TEMPLATE = "templates" -PROVIDERS = ("base", "aws", "azure", "gcp") +PROVIDERS = ("base", "aws", "azure", "gcp", "k8s") ######################### # Resource Processing # @@ -24,7 +24,8 @@ CMD_SVG2PNG_OPTS = ("-z", "-w", "256", "-h", "256", "--export-type", "png") FILE_PREFIXES = { "aws": ("amazon-", "aws-"), "azure": ("azure-",), - "gcp": ("cloud-",) + "gcp": ("cloud-",), + "k8s": (), } ######################### @@ -37,6 +38,9 @@ UPPER_WORDS = { "aws": ("aws", "api", "ebs", "ec2", "efs", "emr", "rds", "ml", "mq", "vpc", "waf"), "azure": ("ad", "b2c", "ai", "api", "cdn", "ddos", "dns", "fxt", "hana", "hd", "id", "sap", "sql", "vm"), "gcp": ("gcp", "ai", "api", "cdn", "dns", "gke", "gpu", "ml", "nat", "os", "sdk", "sql", "tpu", "vpn"), + "k8s": ( + "api", "cm", "ccm", "crb", "crd", "ds", "etcd", "hpa", "ns", "psp", "pv", "pvc", "rb", "rs", "sa", "sc", "sts", + "svc"), } # TODO: check if the classname exists @@ -145,4 +149,46 @@ ALIASES = { "Storage": "GCS", }, }, + "k8s": { + "clusterconfig": { + "Limits": "LimitRange", + "HPA": "HorizontalPodAutoscaler", + }, + "compute": { + "Deploy": "Deployment", + "DS": "DaemonSet", + "RS": "ReplicaSet", + "STS": "StatefulSet" + }, + "controlplane": { + "API": "APIServer", + "CM": "ControllerManager", + "KProxy": "KubeProxy", + "Sched": "Scheduler", + }, + "group": { + "NS": "Namespace", + }, + "network": { + "Ep": "Endpoint", + "Ing": "Ingress", + "Netpol": "NetworkPolicy", + "SVC": "Service", + }, + "podconfig": { + "CM": "ConfigMap", + }, + "rbac": { + "CRole": "ClusterRole", + "CRB": "ClusterRoleBinding", + "RB": "RoleBinding", + "SA": "ServiceAccount", + }, + "storage": { + "PV": "PersistnetVolume", + "PVC": "PersistentVolumeClaim", + "SC": "StorageClass", + "Vol": "Volume", + }, + } } diff --git a/diagrams/k8s/__init__.py b/diagrams/k8s/__init__.py new file mode 100644 index 0000000..6a137b4 --- /dev/null +++ b/diagrams/k8s/__init__.py @@ -0,0 +1,12 @@ +""" +K8S provides a set of services for Kubernetes. +""" + +from diagrams import Node + + +class _K8S(Node): + _provider = "k8s" + _icon_dir = "resources/k8s" + + fontcolor = "#2d3436" diff --git a/diagrams/k8s/clusterconfig.py b/diagrams/k8s/clusterconfig.py new file mode 100644 index 0000000..5a6e392 --- /dev/null +++ b/diagrams/k8s/clusterconfig.py @@ -0,0 +1,26 @@ +# This module is automatically generated by autogen.sh. DO NOT EDIT. + +from . import _K8S + + +class _Clusterconfig(_K8S): + _type = "clusterconfig" + _icon_dir = "resources/k8s/clusterconfig" + + +class HPA(_Clusterconfig): + _icon = "hpa.png" + + +class Limits(_Clusterconfig): + _icon = "limits.png" + + +class Quota(_Clusterconfig): + _icon = "quota.png" + + +# Aliases + +LimitRange = Limits +HorizontalPodAutoscaler = HPA diff --git a/diagrams/k8s/compute.py b/diagrams/k8s/compute.py new file mode 100644 index 0000000..a8078b2 --- /dev/null +++ b/diagrams/k8s/compute.py @@ -0,0 +1,44 @@ +# This module is automatically generated by autogen.sh. DO NOT EDIT. + +from . import _K8S + + +class _Compute(_K8S): + _type = "compute" + _icon_dir = "resources/k8s/compute" + + +class Cronjob(_Compute): + _icon = "cronjob.png" + + +class Deploy(_Compute): + _icon = "deploy.png" + + +class DS(_Compute): + _icon = "ds.png" + + +class Job(_Compute): + _icon = "job.png" + + +class Pod(_Compute): + _icon = "pod.png" + + +class RS(_Compute): + _icon = "rs.png" + + +class STS(_Compute): + _icon = "sts.png" + + +# Aliases + +Deployment = Deploy +DaemonSet = DS +ReplicaSet = RS +StatefulSet = STS diff --git a/diagrams/k8s/controlplane.py b/diagrams/k8s/controlplane.py new file mode 100644 index 0000000..8fa11da --- /dev/null +++ b/diagrams/k8s/controlplane.py @@ -0,0 +1,40 @@ +# This module is automatically generated by autogen.sh. DO NOT EDIT. + +from . import _K8S + + +class _Controlplane(_K8S): + _type = "controlplane" + _icon_dir = "resources/k8s/controlplane" + + +class API(_Controlplane): + _icon = "api.png" + + +class CCM(_Controlplane): + _icon = "c-c-m.png" + + +class CM(_Controlplane): + _icon = "c-m.png" + + +class KProxy(_Controlplane): + _icon = "k-proxy.png" + + +class Kubelet(_Controlplane): + _icon = "kubelet.png" + + +class Sched(_Controlplane): + _icon = "sched.png" + + +# Aliases + +APIServer = API +ControllerManager = CM +KubeProxy = KProxy +Scheduler = Sched diff --git a/diagrams/k8s/group.py b/diagrams/k8s/group.py new file mode 100644 index 0000000..cb0072a --- /dev/null +++ b/diagrams/k8s/group.py @@ -0,0 +1,17 @@ +# This module is automatically generated by autogen.sh. DO NOT EDIT. + +from . import _K8S + + +class _Group(_K8S): + _type = "group" + _icon_dir = "resources/k8s/group" + + +class NS(_Group): + _icon = "ns.png" + + +# Aliases + +Namespace = NS diff --git a/diagrams/k8s/infra.py b/diagrams/k8s/infra.py new file mode 100644 index 0000000..aa8fed8 --- /dev/null +++ b/diagrams/k8s/infra.py @@ -0,0 +1,23 @@ +# This module is automatically generated by autogen.sh. DO NOT EDIT. + +from . import _K8S + + +class _Infra(_K8S): + _type = "infra" + _icon_dir = "resources/k8s/infra" + + +class ETCD(_Infra): + _icon = "etcd.png" + + +class Master(_Infra): + _icon = "master.png" + + +class Node(_Infra): + _icon = "node.png" + + +# Aliases diff --git a/diagrams/k8s/network.py b/diagrams/k8s/network.py new file mode 100644 index 0000000..7436f54 --- /dev/null +++ b/diagrams/k8s/network.py @@ -0,0 +1,32 @@ +# This module is automatically generated by autogen.sh. DO NOT EDIT. + +from . import _K8S + + +class _Network(_K8S): + _type = "network" + _icon_dir = "resources/k8s/network" + + +class Ep(_Network): + _icon = "ep.png" + + +class Ing(_Network): + _icon = "ing.png" + + +class Netpol(_Network): + _icon = "netpol.png" + + +class SVC(_Network): + _icon = "svc.png" + + +# Aliases + +Endpoint = Ep +Ingress = Ing +NetworkPolicy = Netpol +Service = SVC diff --git a/diagrams/k8s/others.py b/diagrams/k8s/others.py new file mode 100644 index 0000000..9a3e9c0 --- /dev/null +++ b/diagrams/k8s/others.py @@ -0,0 +1,19 @@ +# This module is automatically generated by autogen.sh. DO NOT EDIT. + +from . import _K8S + + +class _Others(_K8S): + _type = "others" + _icon_dir = "resources/k8s/others" + + +class CRD(_Others): + _icon = "crd.png" + + +class PSP(_Others): + _icon = "psp.png" + + +# Aliases diff --git a/diagrams/k8s/podconfig.py b/diagrams/k8s/podconfig.py new file mode 100644 index 0000000..4e50c20 --- /dev/null +++ b/diagrams/k8s/podconfig.py @@ -0,0 +1,21 @@ +# This module is automatically generated by autogen.sh. DO NOT EDIT. + +from . import _K8S + + +class _Podconfig(_K8S): + _type = "podconfig" + _icon_dir = "resources/k8s/podconfig" + + +class CM(_Podconfig): + _icon = "cm.png" + + +class Secret(_Podconfig): + _icon = "secret.png" + + +# Aliases + +ConfigMap = CM diff --git a/diagrams/k8s/rbac.py b/diagrams/k8s/rbac.py new file mode 100644 index 0000000..4d17f84 --- /dev/null +++ b/diagrams/k8s/rbac.py @@ -0,0 +1,44 @@ +# This module is automatically generated by autogen.sh. DO NOT EDIT. + +from . import _K8S + + +class _Rbac(_K8S): + _type = "rbac" + _icon_dir = "resources/k8s/rbac" + + +class CRole(_Rbac): + _icon = "c-role.png" + + +class CRB(_Rbac): + _icon = "crb.png" + + +class Group(_Rbac): + _icon = "group.png" + + +class RB(_Rbac): + _icon = "rb.png" + + +class Role(_Rbac): + _icon = "role.png" + + +class SA(_Rbac): + _icon = "sa.png" + + +class User(_Rbac): + _icon = "user.png" + + +# Aliases + +ClusterRole = CRole +ClusterRoleBinding = CRB +RoleBinding = RB +ServiceAccount = SA diff --git a/diagrams/k8s/storage.py b/diagrams/k8s/storage.py new file mode 100644 index 0000000..49d962c --- /dev/null +++ b/diagrams/k8s/storage.py @@ -0,0 +1,32 @@ +# This module is automatically generated by autogen.sh. DO NOT EDIT. + +from . import _K8S + + +class _Storage(_K8S): + _type = "storage" + _icon_dir = "resources/k8s/storage" + + +class PV(_Storage): + _icon = "pv.png" + + +class PVC(_Storage): + _icon = "pvc.png" + + +class SC(_Storage): + _icon = "sc.png" + + +class Vol(_Storage): + _icon = "vol.png" + + +# Aliases + +PersistnetVolume = PV +PersistentVolumeClaim = PVC +StorageClass = SC +Volume = Vol diff --git a/docs/examples.md b/docs/examples.md index 7643582..779932a 100644 --- a/docs/examples.md +++ b/docs/examples.md @@ -126,3 +126,46 @@ with Diagram("Message Collecting", show=False): ``` ![message collecting diagram](/img/message_collecting_diagram.png) + +## Exposed Pod with 3 Replicas on k8s + +```python +from diagrams import Diagram +from diagrams.k8s.clusterconfig import HPA +from diagrams.k8s.compute import Deployment, Pod, ReplicaSet +from diagrams.k8s.network import Ingress, Service + +with Diagram("Exposed Pod with 3 Replicas", show=False): + net = Ingress("domain.com") >> Service("svc") + net >> [Pod("pod1"), + Pod("pod2"), + Pod("pod3")] << ReplicaSet("rs") << Deployment("dp") << HPA("hpa") + +``` + +![exposed pod with 3 replicas diagram](/img/exposed_pod_with_3_replicas_diagram.png) + +## Stateful Architecture on k8s + +```python +from diagrams import Cluster, Diagram +from diagrams.k8s.compute import Pod, StatefulSet +from diagrams.k8s.network import Service +from diagrams.k8s.storage import PV, PVC, StorageClass + +with Diagram("Stateful Architecture", show=False): + with Cluster("App Cluster"): + svc = Service("svc") + sts = StatefulSet("sts") + + apps = [] + for _ in range(3): + pod = Pod("pod") + pvc = PVC("pvc") + pod - sts - pvc + apps.append(svc >> pod >> pvc) + + apps << PV("pv") << StorageClass("sc") +``` + +![stateful architecture diagram](/img/stateful_architecture_diagram.png) diff --git a/resources/k8s/clusterconfig/hpa.png b/resources/k8s/clusterconfig/hpa.png new file mode 100644 index 0000000..0caccb5 Binary files /dev/null and b/resources/k8s/clusterconfig/hpa.png differ diff --git a/resources/k8s/clusterconfig/limits.png b/resources/k8s/clusterconfig/limits.png new file mode 100644 index 0000000..2addd0a Binary files /dev/null and b/resources/k8s/clusterconfig/limits.png differ diff --git a/resources/k8s/clusterconfig/quota.png b/resources/k8s/clusterconfig/quota.png new file mode 100644 index 0000000..a4d4957 Binary files /dev/null and b/resources/k8s/clusterconfig/quota.png differ diff --git a/resources/k8s/compute/cronjob.png b/resources/k8s/compute/cronjob.png new file mode 100644 index 0000000..e70aedd Binary files /dev/null and b/resources/k8s/compute/cronjob.png differ diff --git a/resources/k8s/compute/deploy.png b/resources/k8s/compute/deploy.png new file mode 100644 index 0000000..c32b6b9 Binary files /dev/null and b/resources/k8s/compute/deploy.png differ diff --git a/resources/k8s/compute/ds.png b/resources/k8s/compute/ds.png new file mode 100644 index 0000000..f327daa Binary files /dev/null and b/resources/k8s/compute/ds.png differ diff --git a/resources/k8s/compute/job.png b/resources/k8s/compute/job.png new file mode 100644 index 0000000..e6c2a38 Binary files /dev/null and b/resources/k8s/compute/job.png differ diff --git a/resources/k8s/compute/pod.png b/resources/k8s/compute/pod.png new file mode 100644 index 0000000..e498a9a Binary files /dev/null and b/resources/k8s/compute/pod.png differ diff --git a/resources/k8s/compute/rs.png b/resources/k8s/compute/rs.png new file mode 100644 index 0000000..0e7863b Binary files /dev/null and b/resources/k8s/compute/rs.png differ diff --git a/resources/k8s/compute/sts.png b/resources/k8s/compute/sts.png new file mode 100644 index 0000000..71b46b9 Binary files /dev/null and b/resources/k8s/compute/sts.png differ diff --git a/resources/k8s/controlplane/api.png b/resources/k8s/controlplane/api.png new file mode 100644 index 0000000..868ac54 Binary files /dev/null and b/resources/k8s/controlplane/api.png differ diff --git a/resources/k8s/controlplane/c-c-m.png b/resources/k8s/controlplane/c-c-m.png new file mode 100644 index 0000000..5afab25 Binary files /dev/null and b/resources/k8s/controlplane/c-c-m.png differ diff --git a/resources/k8s/controlplane/c-m.png b/resources/k8s/controlplane/c-m.png new file mode 100644 index 0000000..b30692f Binary files /dev/null and b/resources/k8s/controlplane/c-m.png differ diff --git a/resources/k8s/controlplane/k-proxy.png b/resources/k8s/controlplane/k-proxy.png new file mode 100644 index 0000000..e927817 Binary files /dev/null and b/resources/k8s/controlplane/k-proxy.png differ diff --git a/resources/k8s/controlplane/kubelet.png b/resources/k8s/controlplane/kubelet.png new file mode 100644 index 0000000..462ea49 Binary files /dev/null and b/resources/k8s/controlplane/kubelet.png differ diff --git a/resources/k8s/controlplane/sched.png b/resources/k8s/controlplane/sched.png new file mode 100644 index 0000000..be33ffe Binary files /dev/null and b/resources/k8s/controlplane/sched.png differ diff --git a/resources/k8s/group/ns.png b/resources/k8s/group/ns.png new file mode 100644 index 0000000..9fafbfc Binary files /dev/null and b/resources/k8s/group/ns.png differ diff --git a/resources/k8s/infra/etcd.png b/resources/k8s/infra/etcd.png new file mode 100644 index 0000000..f514ef5 Binary files /dev/null and b/resources/k8s/infra/etcd.png differ diff --git a/resources/k8s/infra/master.png b/resources/k8s/infra/master.png new file mode 100644 index 0000000..074f54e Binary files /dev/null and b/resources/k8s/infra/master.png differ diff --git a/resources/k8s/infra/node.png b/resources/k8s/infra/node.png new file mode 100644 index 0000000..62befbf Binary files /dev/null and b/resources/k8s/infra/node.png differ diff --git a/resources/k8s/network/ep.png b/resources/k8s/network/ep.png new file mode 100644 index 0000000..68fb673 Binary files /dev/null and b/resources/k8s/network/ep.png differ diff --git a/resources/k8s/network/ing.png b/resources/k8s/network/ing.png new file mode 100644 index 0000000..8fe0217 Binary files /dev/null and b/resources/k8s/network/ing.png differ diff --git a/resources/k8s/network/netpol.png b/resources/k8s/network/netpol.png new file mode 100644 index 0000000..67bd640 Binary files /dev/null and b/resources/k8s/network/netpol.png differ diff --git a/resources/k8s/network/svc.png b/resources/k8s/network/svc.png new file mode 100644 index 0000000..8cca480 Binary files /dev/null and b/resources/k8s/network/svc.png differ diff --git a/resources/k8s/others/crd.png b/resources/k8s/others/crd.png new file mode 100644 index 0000000..ead4e03 Binary files /dev/null and b/resources/k8s/others/crd.png differ diff --git a/resources/k8s/others/psp.png b/resources/k8s/others/psp.png new file mode 100644 index 0000000..57dce56 Binary files /dev/null and b/resources/k8s/others/psp.png differ diff --git a/resources/k8s/podconfig/cm.png b/resources/k8s/podconfig/cm.png new file mode 100644 index 0000000..4f1c049 Binary files /dev/null and b/resources/k8s/podconfig/cm.png differ diff --git a/resources/k8s/podconfig/secret.png b/resources/k8s/podconfig/secret.png new file mode 100644 index 0000000..e7a8b3e Binary files /dev/null and b/resources/k8s/podconfig/secret.png differ diff --git a/resources/k8s/rbac/c-role.png b/resources/k8s/rbac/c-role.png new file mode 100644 index 0000000..ebc7bcf Binary files /dev/null and b/resources/k8s/rbac/c-role.png differ diff --git a/resources/k8s/rbac/crb.png b/resources/k8s/rbac/crb.png new file mode 100644 index 0000000..c0a51dc Binary files /dev/null and b/resources/k8s/rbac/crb.png differ diff --git a/resources/k8s/rbac/group.png b/resources/k8s/rbac/group.png new file mode 100644 index 0000000..87ff596 Binary files /dev/null and b/resources/k8s/rbac/group.png differ diff --git a/resources/k8s/rbac/rb.png b/resources/k8s/rbac/rb.png new file mode 100644 index 0000000..9708823 Binary files /dev/null and b/resources/k8s/rbac/rb.png differ diff --git a/resources/k8s/rbac/role.png b/resources/k8s/rbac/role.png new file mode 100644 index 0000000..df45e45 Binary files /dev/null and b/resources/k8s/rbac/role.png differ diff --git a/resources/k8s/rbac/sa.png b/resources/k8s/rbac/sa.png new file mode 100644 index 0000000..e642f37 Binary files /dev/null and b/resources/k8s/rbac/sa.png differ diff --git a/resources/k8s/rbac/user.png b/resources/k8s/rbac/user.png new file mode 100644 index 0000000..e788605 Binary files /dev/null and b/resources/k8s/rbac/user.png differ diff --git a/resources/k8s/storage/pv.png b/resources/k8s/storage/pv.png new file mode 100644 index 0000000..9a0bbaf Binary files /dev/null and b/resources/k8s/storage/pv.png differ diff --git a/resources/k8s/storage/pvc.png b/resources/k8s/storage/pvc.png new file mode 100644 index 0000000..de66402 Binary files /dev/null and b/resources/k8s/storage/pvc.png differ diff --git a/resources/k8s/storage/sc.png b/resources/k8s/storage/sc.png new file mode 100644 index 0000000..63f8518 Binary files /dev/null and b/resources/k8s/storage/sc.png differ diff --git a/resources/k8s/storage/vol.png b/resources/k8s/storage/vol.png new file mode 100644 index 0000000..c47cc2d Binary files /dev/null and b/resources/k8s/storage/vol.png differ diff --git a/scripts/resource.py b/scripts/resource.py index 79b1571..5d43495 100644 --- a/scripts/resource.py +++ b/scripts/resource.py @@ -47,10 +47,20 @@ def cleaner_gcp(f): return f.lower() +def cleaner_k8s(f): + f = f.replace("-256", "") + for p in cfg.FILE_PREFIXES["k8s"]: + if f.startswith(p): + f = f[len(p):] + break + return f.lower() + + cleaners = { "aws": cleaner_aws, "azure": cleaner_azure, "gcp": cleaner_gcp, + "k8s": cleaner_k8s, } diff --git a/website/pages/en/index.js b/website/pages/en/index.js index ae93b5d..6af4c39 100644 --- a/website/pages/en/index.js +++ b/website/pages/en/index.js @@ -106,7 +106,7 @@ class Index extends React.Component { `Diagram as Code` allows you to **tracking** the architecture diagram changes on any **version control** system. - Diagrams currently supports three major cloud providers: `AWS`, `Azure`, `GCP`. + Diagrams currently supports four major providers: `AWS`, `Azure`, `GCP` and `Kubernetes`. ); diff --git a/website/static/img/exposed_pod_with_3_replicas_diagram.png b/website/static/img/exposed_pod_with_3_replicas_diagram.png new file mode 100644 index 0000000..b99dab3 Binary files /dev/null and b/website/static/img/exposed_pod_with_3_replicas_diagram.png differ diff --git a/website/static/img/stateful_architecture_diagram.png b/website/static/img/stateful_architecture_diagram.png new file mode 100644 index 0000000..d0ad6cc Binary files /dev/null and b/website/static/img/stateful_architecture_diagram.png differ