瀏覽代碼

feat: support k8s diagrams

tags/v0.2.0
mingrammer 4 年之前
父節點
當前提交
3eda1cb6bc
共有 58 個文件被更改,包括 419 次插入8 次删除
  1. +6
    -4
      README.md
  2. +1
    -1
      autogen.sh
  3. +48
    -2
      config.py
  4. +12
    -0
      diagrams/k8s/__init__.py
  5. +26
    -0
      diagrams/k8s/clusterconfig.py
  6. +44
    -0
      diagrams/k8s/compute.py
  7. +40
    -0
      diagrams/k8s/controlplane.py
  8. +17
    -0
      diagrams/k8s/group.py
  9. +23
    -0
      diagrams/k8s/infra.py
  10. +32
    -0
      diagrams/k8s/network.py
  11. +19
    -0
      diagrams/k8s/others.py
  12. +21
    -0
      diagrams/k8s/podconfig.py
  13. +44
    -0
      diagrams/k8s/rbac.py
  14. +32
    -0
      diagrams/k8s/storage.py
  15. +43
    -0
      docs/examples.md
  16. 二進制
      resources/k8s/clusterconfig/hpa.png
  17. 二進制
      resources/k8s/clusterconfig/limits.png
  18. 二進制
      resources/k8s/clusterconfig/quota.png
  19. 二進制
      resources/k8s/compute/cronjob.png
  20. 二進制
      resources/k8s/compute/deploy.png
  21. 二進制
      resources/k8s/compute/ds.png
  22. 二進制
      resources/k8s/compute/job.png
  23. 二進制
      resources/k8s/compute/pod.png
  24. 二進制
      resources/k8s/compute/rs.png
  25. 二進制
      resources/k8s/compute/sts.png
  26. 二進制
      resources/k8s/controlplane/api.png
  27. 二進制
      resources/k8s/controlplane/c-c-m.png
  28. 二進制
      resources/k8s/controlplane/c-m.png
  29. 二進制
      resources/k8s/controlplane/k-proxy.png
  30. 二進制
      resources/k8s/controlplane/kubelet.png
  31. 二進制
      resources/k8s/controlplane/sched.png
  32. 二進制
      resources/k8s/group/ns.png
  33. 二進制
      resources/k8s/infra/etcd.png
  34. 二進制
      resources/k8s/infra/master.png
  35. 二進制
      resources/k8s/infra/node.png
  36. 二進制
      resources/k8s/network/ep.png
  37. 二進制
      resources/k8s/network/ing.png
  38. 二進制
      resources/k8s/network/netpol.png
  39. 二進制
      resources/k8s/network/svc.png
  40. 二進制
      resources/k8s/others/crd.png
  41. 二進制
      resources/k8s/others/psp.png
  42. 二進制
      resources/k8s/podconfig/cm.png
  43. 二進制
      resources/k8s/podconfig/secret.png
  44. 二進制
      resources/k8s/rbac/c-role.png
  45. 二進制
      resources/k8s/rbac/crb.png
  46. 二進制
      resources/k8s/rbac/group.png
  47. 二進制
      resources/k8s/rbac/rb.png
  48. 二進制
      resources/k8s/rbac/role.png
  49. 二進制
      resources/k8s/rbac/sa.png
  50. 二進制
      resources/k8s/rbac/user.png
  51. 二進制
      resources/k8s/storage/pv.png
  52. 二進制
      resources/k8s/storage/pvc.png
  53. 二進制
      resources/k8s/storage/sc.png
  54. 二進制
      resources/k8s/storage/vol.png
  55. +10
    -0
      scripts/resource.py
  56. +1
    -1
      website/pages/en/index.js
  57. 二進制
      website/static/img/exposed_pod_with_3_replicas_diagram.png
  58. 二進制
      website/static/img/stateful_architecture_diagram.png

+ 6
- 4
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.



+ 1
- 1
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'


+ 48
- 2
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",
},
}
}

+ 12
- 0
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"

+ 26
- 0
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

+ 44
- 0
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

+ 40
- 0
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

+ 17
- 0
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

+ 23
- 0
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

+ 32
- 0
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

+ 19
- 0
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

+ 21
- 0
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

+ 44
- 0
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

+ 32
- 0
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

+ 43
- 0
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)

二進制
resources/k8s/clusterconfig/hpa.png 查看文件

Before After
Width: 256  |  Height: 256  |  Size: 14 KiB

二進制
resources/k8s/clusterconfig/limits.png 查看文件

Before After
Width: 256  |  Height: 256  |  Size: 12 KiB

二進制
resources/k8s/clusterconfig/quota.png 查看文件

Before After
Width: 256  |  Height: 256  |  Size: 19 KiB

二進制
resources/k8s/compute/cronjob.png 查看文件

Before After
Width: 256  |  Height: 256  |  Size: 15 KiB

二進制
resources/k8s/compute/deploy.png 查看文件

Before After
Width: 256  |  Height: 256  |  Size: 17 KiB

二進制
resources/k8s/compute/ds.png 查看文件

Before After
Width: 256  |  Height: 256  |  Size: 12 KiB

二進制
resources/k8s/compute/job.png 查看文件

Before After
Width: 256  |  Height: 256  |  Size: 11 KiB

二進制
resources/k8s/compute/pod.png 查看文件

Before After
Width: 256  |  Height: 256  |  Size: 14 KiB

二進制
resources/k8s/compute/rs.png 查看文件

Before After
Width: 256  |  Height: 256  |  Size: 11 KiB

二進制
resources/k8s/compute/sts.png 查看文件

Before After
Width: 256  |  Height: 256  |  Size: 14 KiB

二進制
resources/k8s/controlplane/api.png 查看文件

Before After
Width: 256  |  Height: 256  |  Size: 18 KiB

二進制
resources/k8s/controlplane/c-c-m.png 查看文件

Before After
Width: 256  |  Height: 256  |  Size: 18 KiB

二進制
resources/k8s/controlplane/c-m.png 查看文件

Before After
Width: 256  |  Height: 256  |  Size: 18 KiB

二進制
resources/k8s/controlplane/k-proxy.png 查看文件

Before After
Width: 256  |  Height: 256  |  Size: 20 KiB

二進制
resources/k8s/controlplane/kubelet.png 查看文件

Before After
Width: 256  |  Height: 256  |  Size: 19 KiB

二進制
resources/k8s/controlplane/sched.png 查看文件

Before After
Width: 256  |  Height: 256  |  Size: 20 KiB

二進制
resources/k8s/group/ns.png 查看文件

Before After
Width: 256  |  Height: 256  |  Size: 12 KiB

二進制
resources/k8s/infra/etcd.png 查看文件

Before After
Width: 256  |  Height: 256  |  Size: 19 KiB

二進制
resources/k8s/infra/master.png 查看文件

Before After
Width: 256  |  Height: 256  |  Size: 20 KiB

二進制
resources/k8s/infra/node.png 查看文件

Before After
Width: 256  |  Height: 256  |  Size: 19 KiB

二進制
resources/k8s/network/ep.png 查看文件

Before After
Width: 256  |  Height: 256  |  Size: 14 KiB

二進制
resources/k8s/network/ing.png 查看文件

Before After
Width: 256  |  Height: 256  |  Size: 15 KiB

二進制
resources/k8s/network/netpol.png 查看文件

Before After
Width: 256  |  Height: 256  |  Size: 16 KiB

二進制
resources/k8s/network/svc.png 查看文件

Before After
Width: 256  |  Height: 256  |  Size: 12 KiB

二進制
resources/k8s/others/crd.png 查看文件

Before After
Width: 256  |  Height: 256  |  Size: 13 KiB

二進制
resources/k8s/others/psp.png 查看文件

Before After
Width: 256  |  Height: 256  |  Size: 15 KiB

二進制
resources/k8s/podconfig/cm.png 查看文件

Before After
Width: 256  |  Height: 256  |  Size: 11 KiB

二進制
resources/k8s/podconfig/secret.png 查看文件

Before After
Width: 256  |  Height: 256  |  Size: 14 KiB

二進制
resources/k8s/rbac/c-role.png 查看文件

Before After
Width: 256  |  Height: 256  |  Size: 14 KiB

二進制
resources/k8s/rbac/crb.png 查看文件

Before After
Width: 256  |  Height: 256  |  Size: 13 KiB

二進制
resources/k8s/rbac/group.png 查看文件

Before After
Width: 256  |  Height: 256  |  Size: 15 KiB

二進制
resources/k8s/rbac/rb.png 查看文件

Before After
Width: 256  |  Height: 256  |  Size: 14 KiB

二進制
resources/k8s/rbac/role.png 查看文件

Before After
Width: 256  |  Height: 256  |  Size: 16 KiB

二進制
resources/k8s/rbac/sa.png 查看文件

Before After
Width: 256  |  Height: 256  |  Size: 15 KiB

二進制
resources/k8s/rbac/user.png 查看文件

Before After
Width: 256  |  Height: 256  |  Size: 13 KiB

二進制
resources/k8s/storage/pv.png 查看文件

Before After
Width: 256  |  Height: 256  |  Size: 13 KiB

二進制
resources/k8s/storage/pvc.png 查看文件

Before After
Width: 256  |  Height: 256  |  Size: 16 KiB

二進制
resources/k8s/storage/sc.png 查看文件

Before After
Width: 256  |  Height: 256  |  Size: 18 KiB

二進制
resources/k8s/storage/vol.png 查看文件

Before After
Width: 256  |  Height: 256  |  Size: 13 KiB

+ 10
- 0
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,
}




+ 1
- 1
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.
</MarkdownBlock>
<MarkdownBlock>
Diagrams currently supports three major cloud providers: `AWS`, `Azure`, `GCP`.
Diagrams currently supports four major providers: `AWS`, `Azure`, `GCP` and `Kubernetes`.
</MarkdownBlock>
</div>
);


二進制
website/static/img/exposed_pod_with_3_replicas_diagram.png 查看文件

Before After
Width: 1039  |  Height: 528  |  Size: 62 KiB

二進制
website/static/img/stateful_architecture_diagram.png 查看文件

Before After
Width: 1070  |  Height: 572  |  Size: 91 KiB

Loading…
取消
儲存