feat: support k8s diagrams

pull/11/head
mingrammer 6 years ago
parent 994db50607
commit 3eda1cb6bc

@ -4,7 +4,7 @@
**Diagram as Code**. **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. **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 ## Examples
| Grouped Workers | Clustered Web Services | Event Processing | | 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](https://diagrams.mingrammer.com/img/event_processing_diagram.png) | | ![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. You can find all the examples on the [examples](https://diagrams.mingrammer.com/docs/examples) page.

@ -2,7 +2,7 @@
app_root_dir="diagrams" app_root_dir="diagrams"
# NOTE: azure icon set is not latest version # NOTE: azure icon set is not latest version
providers=("aws" "azure" "gcp") providers=("aws" "azure" "gcp" "k8s")
if ! [ -x "$(command -v round)" ]; then if ! [ -x "$(command -v round)" ]; then
echo 'round is not installed' echo 'round is not installed'

@ -10,7 +10,7 @@ DIR_APP_ROOT = "diagrams"
DIR_RESOURCE = "resources" DIR_RESOURCE = "resources"
DIR_TEMPLATE = "templates" DIR_TEMPLATE = "templates"
PROVIDERS = ("base", "aws", "azure", "gcp") PROVIDERS = ("base", "aws", "azure", "gcp", "k8s")
######################### #########################
# Resource Processing # # Resource Processing #
@ -24,7 +24,8 @@ CMD_SVG2PNG_OPTS = ("-z", "-w", "256", "-h", "256", "--export-type", "png")
FILE_PREFIXES = { FILE_PREFIXES = {
"aws": ("amazon-", "aws-"), "aws": ("amazon-", "aws-"),
"azure": ("azure-",), "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"), "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"), "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"), "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 # TODO: check if the classname exists
@ -145,4 +149,46 @@ ALIASES = {
"Storage": "GCS", "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",
},
}
} }

@ -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"

@ -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

@ -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

@ -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

@ -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

@ -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

@ -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

@ -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

@ -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

@ -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

@ -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

@ -126,3 +126,46 @@ with Diagram("Message Collecting", show=False):
``` ```
![message collecting diagram](/img/message_collecting_diagram.png) ![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)

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

@ -47,10 +47,20 @@ def cleaner_gcp(f):
return f.lower() 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 = { cleaners = {
"aws": cleaner_aws, "aws": cleaner_aws,
"azure": cleaner_azure, "azure": cleaner_azure,
"gcp": cleaner_gcp, "gcp": cleaner_gcp,
"k8s": cleaner_k8s,
} }

@ -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. `Diagram as Code` allows you to **tracking** the architecture diagram changes on any **version control** system.
</MarkdownBlock> </MarkdownBlock>
<MarkdownBlock> <MarkdownBlock>
Diagrams currently supports three major cloud providers: `AWS`, `Azure`, `GCP`. Diagrams currently supports four major providers: `AWS`, `Azure`, `GCP` and `Kubernetes`.
</MarkdownBlock> </MarkdownBlock>
</div> </div>
); );

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 91 KiB

Loading…
Cancel
Save