# burlyluo/clab architecture

> Architecture diagram of the GitHub repository burlyluo/clab, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/burlyluo/clab
- Repository: https://github.com/burlyluo/clab

## Overview

##### Project’s Purpose and Type
- This project is a combined network simulation and Kubernetes deployment lab. It leverages KinD (Kubernetes in Docker) to quickly spin up a Kubernetes cluster and uses Containerlab to create simulated network infrastructure (routers, switches, and network nodes) with Docker containers.
- The goal is to demonstrate how to integrate network resources (with distinct subnets created by Containerlab) into a KinD-based Kubernetes environment, further extended with Calico as the CNI plugin.

##### File Structure
- Shell Scripts: Files like Deprecated-kind-calico-svc-bgp.sh, adv-clusterip.sh, and label_node.sh suggest automation scripts around network configuration.
- Containerlab Artifacts: The “clab-bgp-cplane-demo” directory and “topo.yaml” file point to the topology definition of the simulated network environment.
- Network Configurations: The “startup-config” directory holds router configuration files (leaf0.cfg, spine0.cfg, etc.) for the virtual routers defined within Containerlab.
- Overall, the file tree shows a clear separation between Kubernetes orchestrations (KinD, Calico) and network lab topologies (Containerlab specific files and configurations).

##### Main Components
a. KinD-Based Kubernetes Cluster:
- Control Plane Node: “clab-bgp-cplane-demo-control-plane”
- Worker Nodes: “clab-bgp-cplane-demo-worker”, “worker2”, “worker3”
- Calico CNI component configured via calico.yaml (with related CRDs and deployments)

b. Containerlab Network Infrastructure:
- Virtual Routers: Represented by VyOS containers (leaf0, leaf1, spine0, spine1) which have configurations in the startup-config directory.
- Network Nodes/Servers: Linux containers (using burlyluo/nettoolbox image) such as server1, server2, server3, server4.
- Virtual Bridges: “br-leaf0” and “br-leaf1”, which are created in the pre-deployment scripts to provide separate subnets.
- Topology Definition: Highlight that the topology is defined in topo.yaml and evidenced by virtual wires created between interfaces (as shown by the Containerlab logs).

c. Integration Layer:
- That container networking (via Containerlab and Docker networks) supports the creation of distinct subnets and routing for the cluster.

##### Relationships, Interactions, and Data Flow
– How the Kubernetes cluster is deployed using KinD (with a clear flow from “kind create cluster…” to the deployment of both control-plane and worker nodes).
– How Containerlab uses the topo.yaml configuration to instantiate network devices (routers, servers, and bridges), and then connects these virtual devices using “virtual wires”.
– How Calico is applied to provide Kubernetes networking after the integration is completed.
– The integration where one of the server containers (e.g., server1) is re-configured (via container network mode tricks) to tap into the network resources from Containerlab.

##### Architectural Patterns and Design Principles
- It demonstrates the use of infrastructure-as-code for network topology (topo.yaml) and declarative Kubernetes configuration (YAML files for cluster and Calico).
- This division encourages clear separation of concerns: one part focused on container orchestration and the other on network simulation.
- That the network configuration is modular (with per-node configuration files for routers) and that routing decisions are enforced via BGP configurations (bgpconfig.yaml and per-node BGP peer configuration files).

## Diagram (Mermaid)

```mermaid
flowchart TD

    subgraph "KinD (Kubernetes Cluster)"
        KCP["Kubernetes Control Plane"]:::k8s
        WK1["Worker Node 1"]:::k8s
        WK2["Worker Node 2"]:::k8s
        WK3["Worker Node 3"]:::k8s
        Calico["CNI Plugin (Calico)"]:::k8sConfig
        KCP ---|"applies"| Calico
        KCP --- WK1
        KCP --- WK2
        KCP --- WK3
    end

    subgraph "Containerlab Network Lab"
        Topo["Topology Definition (topo.yaml)"]:::config
        TopoDir["Topology Directory"]:::config
        subgraph "Virtual Routers"
            RL0["Router leaf0"]:::netDevice
            RL1["Router leaf1"]:::netDevice
            RS0["Router spine0"]:::netDevice
            RS1["Router spine1"]:::netDevice
        end
        subgraph "Servers & Bridges"
            S1["Server 1"]:::server
            S2["Server 2"]:::server
            S3["Server 3"]:::server
            S4["Server 4"]:::server
            B0["Bridge br-leaf0"]:::bridge
            B1["Bridge br-leaf1"]:::bridge
        end
        TopoDir --> Topo
        Topo -->|"configures"| RL0
        Topo --> S1
    end

    subgraph "Integration & Automation"
        BGP["BGP Configurations"]:::config
        Auto["Automation Scripts"]:::auto
    end

    S1 -->|"integrates"| KCP

    BGP --> RL0
    BGP --> RL1
    BGP --> RS0
    BGP --> RS1

    Auto --- KCP
    Auto --- S1

    classDef k8s fill:#bbf,stroke:#333,stroke-width:2px;
    classDef k8sConfig fill:#99f,stroke:#333,stroke-width:2px;
    classDef netDevice fill:#afa,stroke:#333,stroke-width:2px;
    classDef server fill:#dfd,stroke:#333,stroke-width:2px;
    classDef bridge fill:#efe,stroke:#333,stroke-width:2px;
    classDef config fill:#ff9,stroke:#333,stroke-width:2px;
    classDef auto fill:#f99,stroke:#333,stroke-width:2px

    click KCP "https://github.com/burlyluo/clab/blob/master/clab-bgp-cplane-demo-control-plane.yaml"
    click WK1 "https://github.com/burlyluo/clab/blob/master/clab-bgp-cplane-demo-worker.yaml"
    click WK2 "https://github.com/burlyluo/clab/blob/master/clab-bgp-cplane-demo-worker2.yaml"
    click WK3 "https://github.com/burlyluo/clab/blob/master/clab-bgp-cplane-demo-worker3.yaml"
    click Calico "https://github.com/burlyluo/clab/blob/master/calico.yaml"
    click Calico "https://github.com/burlyluo/clab/blob/master/kind-calico.yaml"
    click Calico "https://github.com/burlyluo/clab/blob/master/cni.yaml"
    click Topo "https://github.com/burlyluo/clab/blob/master/topo.yaml"
    click TopoDir "https://github.com/burlyluo/clab/tree/master/clab-bgp-cplane-demo"
    click RL0 "https://github.com/burlyluo/clab/blob/master/startup-config/leaf0.cfg"
    click RL1 "https://github.com/burlyluo/clab/blob/master/startup-config/leaf1.cfg"
    click RS0 "https://github.com/burlyluo/clab/blob/master/startup-config/spine0.cfg"
    click RS1 "https://github.com/burlyluo/clab/blob/master/startup-config/spine1.cfg"
    click BGP "https://github.com/burlyluo/clab/blob/master/bgpconfig.yaml"
    click BGP "https://github.com/burlyluo/clab/blob/master/per-node-bgppeer_rack1.yaml"
    click BGP "https://github.com/burlyluo/clab/blob/master/per-node-bgppeer_rack2.yaml"
    click Auto "https://github.com/burlyluo/clab/blob/master/Deprecated-kind-calico-svc-bgp.sh"
    click Auto "https://github.com/burlyluo/clab/blob/master/adv-clusterip.sh"
    click Auto "https://github.com/burlyluo/clab/blob/master/label_node.sh"
```
