iT邦幫忙

2024 iThome 鐵人賽

DAY 17
0

前言

  • 昨天我們進行了diagram 和node的介紹,今天我們簡單快速的介紹Cluster以及Edge

正文

Cluster

參考資料:https://diagrams.mingrammer.com/docs/guides/cluster

  • Cluster可以進行雲端架構的分類,每個node都可以連進連出Cluster內的node
from diagrams import Cluster, Diagram
from diagrams.aws.compute import ECS
from diagrams.aws.database import RDS
from diagrams.aws.network import Route53

with Diagram("Simple Web Service with DB Cluster", show=False):
    dns = Route53("dns")
    web = ECS("service")

    with Cluster("DB Cluster"):
        db_primary = RDS("primary")
        db_primary - [RDS("replica1"),
                     RDS("replica2")]

    dns >> web >> db_primary

https://ithelp.ithome.com.tw/upload/images/20240916/201686975CDKh82bhn.png

  • 特別的是這個Cluster也可以進行巢狀
from diagrams import Cluster, Diagram
from diagrams.aws.compute import ECS, EKS, Lambda
from diagrams.aws.database import Redshift
from diagrams.aws.integration import SQS
from diagrams.aws.storage import S3

with Diagram("Event Processing", show=False):
    source = EKS("k8s source")

    with Cluster("Event Flows"):
        with Cluster("Event Workers"):
            workers = [ECS("worker1"),
                       ECS("worker2"),
                       ECS("worker3")]

        queue = SQS("event queue")

        with Cluster("Processing"):
            handlers = [Lambda("proc1"),
                        Lambda("proc2"),
                        Lambda("proc3")]

    store = S3("events store")
    dw = Redshift("analytics")

    source >> workers >> queue >> handlers
    handlers >> store
    handlers >> dw

https://ithelp.ithome.com.tw/upload/images/20240916/20168697vv7lGnvjz9.png

Edge

參考資料:https://diagrams.mingrammer.com/docs/guides/edge

  • edge也有額外的屬性可以用,color和 style 和label
  • style="dashed" 是虛線
  • style="bold" 是粗線
from diagrams import Cluster, Diagram, Edge
from diagrams.aws.network import ELB
from diagrams.aws.compute import EC2
from diagrams.aws.database import RDSPostgresqlInstance
from diagrams.aws.integration import SQS
from diagrams.aws.analytics import ManagedStreamingForKafka as MSK
from diagrams.aws.analytics import Glue
from diagrams.aws.storage import S3
from diagrams.aws.security import Cognito
from diagrams.aws.management import Cloudwatch

with Diagram(name="Advanced Web Service with AWS (colored)", show=False):
    ingress = ELB("Load Balancer")

    metrics = Cloudwatch("CloudWatch")
    metrics << Edge(color="firebrick",
                    style="dashed") << Cloudwatch("Monitoring")

    with Cluster("Service Cluster"):
        grpcsvc = [
            EC2("grpc1"),
            EC2("grpc2"),
            EC2("grpc3")]

    with Cluster("Sessions HA"):
        primary = SQS("SQS Queue")
        primary \
            - Edge(color="brown", style="dashed") \
            - SQS("SQS Queue Replica") \
            << Edge(label="collect") \
            << metrics
        grpcsvc >> Edge(color="brown") >> primary

    with Cluster("Database HA"):
        primary = RDSPostgresqlInstance("RDS Postgres")
        primary \
            - Edge(color="brown", style="dotted") \
            - RDSPostgresqlInstance("RDS Replica") \
            << Edge(label="collect") \
            << metrics
        grpcsvc >> Edge(color="black") >> primary

    aggregator = Glue("Glue Crawler")
    aggregator \
        >> Edge(label="parse") \
        >> MSK("Kafka (MSK)") \
        >> Edge(color="black", style="bold") \
        >> S3("S3 Analytics Storage")

    ingress \
        >> Edge(color="darkgreen") \
        << grpcsvc \
        >> Edge(color="darkorange") \
        >> aggregator

https://ithelp.ithome.com.tw/upload/images/20240916/20168697p6pbrpRwA0.png


上一篇
day16 Diagram as Code API (一) : 圖表與節點
下一篇
day18 Diagram as Code 創建RAG資料庫計畫:製作給予GenAI的教科書
系列文
智能雲端架構圖生成:結合LangChain&LangGrpah與Rag的創新應用30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言