# vg4rc1a/cluster-docker-laboratorio architecture

> Architecture diagram of the GitHub repository vg4rc1a/cluster-docker-laboratorio, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/vg4rc1a/cluster-docker-laboratorio
- Repository: https://github.com/vg4rc1a/cluster-docker-laboratorio

## Overview

#### Purpose and Scope
This repository provisions a three-node Ubuntu Server 22.04 Docker Swarm laboratory. It codifies host preparation, static LAN networking, Docker installation, Swarm formation, node placement metadata, firewall access, and an encrypted overlay network. It is infrastructure automation, not an application service.

#### Execution Entry Points
The ordered shell scripts in `scripts/` are the operational entry points. Bootstrap begins with `scripts/01-keyboard-and-update.sh`, then uses a node-specific network script. Cluster control transitions to the manager through `scripts/05-init-swarm.sh`; workers join through `scripts/06-join-worker.sh`. Manager-side post-formation actions are `scripts/07-labels.sh` and `scripts/08-test-service.sh`.

#### Host and Network Foundation
Each VM receives a fixed Netplan configuration selected by role: `configs/netplan/manager.yaml`, `configs/netplan/worker01.yaml`, and `configs/netplan/worker02.yaml`. The manager is the Swarm control-plane endpoint at `192.168.1.101`; workers use `192.168.1.104` and `.105`. pfSense is an external gateway/firewall on the same LAN, so host reachability and Swarm traffic depend on that network boundary.

Network configuration is applied through `scripts/02-network-manager.sh`, `scripts/02-network-worker01.sh`, and `scripts/02-network-worker02.sh`. Shared hostname resolution material is provided by `configs/hosts-snippet.txt`.

#### Docker Runtime and Host Security
Docker Engine is installed consistently on every node via `scripts/03-install-docker.sh`; daemon-level behavior is centrally represented by `configs/daemon.json`. Host firewall policy is applied by `scripts/04-firewall.sh`.

UFW is the principal security boundary on the nodes. It must permit administrative SSH and published HTTP(S) traffic, plus Swarm manager control traffic, node gossip, and VXLAN overlay transport. pfSense provides the upstream LAN/WAN routing boundary.

#### Swarm Control Plane and Membership
`scripts/05-init-swarm.sh` initializes the manager and establishes the manager’s advertised endpoint. This creates the cluster control plane and emits the worker join material. `scripts/06-join-worker.sh` consumes a join token and manager address to attach each worker.

The intended topology is one manager/leader and two workers. The manager schedules and administers services; workers execute assigned tasks. Cluster lifecycle commands and verification guidance are retained in `docs/admin-commands.md` and observed cluster state in `docs/swarm-output.md`.

#### Scheduling and Service Networking
`scripts/07-labels.sh` assigns Swarm node labels after all members are present. Those labels are the placement-policy boundary for future stack/service constraints.

`stacks/production-net.sh` creates the encrypted Swarm overlay network used for cross-node container communication. Services attached to this network communicate over Docker’s overlay/VXLAN transport rather than relying on direct container host networking. `scripts/08-test-service.sh` deploys the Nginx validation workload to confirm scheduling, service discovery/networking, and published access.

#### Operational Flow
The dependency sequence is: prepare each OS → configure static network identity → install/configure Docker → open node firewall ports → initialize manager → join workers → label nodes → create/use overlay networking → deploy validation service. Setup and recovery-oriented operator instructions are concentrated in `docs/setup.md`.

Main entry points: [`scripts/03-install-docker.sh`](https://github.com/vg4rc1a/cluster-docker-laboratorio/blob/main/scripts/03-install-docker.sh) (Install Docker Engine), [`scripts/05-init-swarm.sh`](https://github.com/vg4rc1a/cluster-docker-laboratorio/blob/main/scripts/05-init-swarm.sh) (Initialize manager), [`scripts/01-keyboard-and-update.sh`](https://github.com/vg4rc1a/cluster-docker-laboratorio/blob/main/scripts/01-keyboard-and-update.sh) (OS bootstrap), [`configs/daemon.json`](https://github.com/vg4rc1a/cluster-docker-laboratorio/blob/main/configs/daemon.json) (Docker daemon config)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_host["Host Foundation"]
  node_setup_docs["Setup guidance<br/>operator docs<br/>[setup.md]"]
  node_bootstrap["OS bootstrap<br/>shell script"]
  node_docker_install["Install Docker Engine<br/>shell script"]
  node_daemon_config["Docker daemon config<br/>daemon configuration<br/>[daemon.json]"]
end

subgraph group_network["LAN and Security"]
  node_netplan["Role Netplan configs<br/>Netplan YAML"]
  node_network_scripts["Apply node networking<br/>shell scripts"]
  node_hosts_snippet["Shared host resolution<br/>hosts snippet<br/>[hosts-snippet.txt]"]
  node_pfsense{{"pfSense gateway<br/>external firewall"}}
  node_firewall_script["Apply UFW policy<br/>shell script<br/>[04-firewall.sh]"]
  node_ufw{{"Node firewall<br/>UFW"}}
end

subgraph group_swarm["Swarm Control Plane"]
  node_init_swarm["Initialize manager<br/>shell script<br/>[05-init-swarm.sh]"]
  node_manager(("Manager / leader<br/>Swarm manager"))
  node_join_workers["Join workers<br/>shell script<br/>[06-join-worker.sh]"]
  node_workers(("Worker nodes<br/>Swarm workers"))
  node_labels["Assign node labels<br/>shell script<br/>[07-labels.sh]"]
  node_admin_docs["Cluster operations records<br/>operator docs"]
end

subgraph group_workload["Service Validation"]
  node_overlay["Encrypted overlay network<br/>Swarm overlay<br/>[production-net.sh]"]
  node_test_service["Deploy validation service<br/>shell script<br/>[08-test-service.sh]"]
  node_nginx["Nginx validation workload<br/>Swarm service"]
end

node_setup_docs -.->|"ordered procedure"| node_bootstrap
node_bootstrap -->|"prepare hosts"| node_network_scripts
node_netplan -->|"role-specific inputs"| node_network_scripts
node_hosts_snippet -->|"hostname resolution"| node_network_scripts
node_network_scripts -->|"connects to LAN"| node_pfsense
node_network_scripts -->|"network ready"| node_docker_install
node_docker_install -->|"configures runtime"| node_daemon_config
node_daemon_config -->|"runtime ready"| node_firewall_script
node_firewall_script -->|"applies policy"| node_ufw
node_ufw -.->|"host and upstream boundaries"| node_pfsense
node_docker_install -->|"Docker available"| node_init_swarm
node_ufw -->|"permits control traffic"| node_init_swarm
node_init_swarm -->|"creates control plane"| node_manager
node_manager -->|"issues join material"| node_join_workers
node_join_workers -->|"attaches members"| node_workers
node_ufw -->|"permits gossip and VXLAN"| node_workers
node_workers -->|"members present"| node_labels
node_labels -->|"placement metadata"| node_manager
node_manager -.->|"operated and verified by"| node_admin_docs
node_manager -->|"creates network"| node_overlay
node_overlay -->|"cross-node connectivity"| node_nginx
node_test_service -->|"deploys"| node_nginx
node_manager -->|"schedules deployment"| node_test_service
node_workers -->|"execute tasks"| node_nginx

click node_setup_docs "https://github.com/vg4rc1a/cluster-docker-laboratorio/blob/main/docs/setup.md"
click node_bootstrap "https://github.com/vg4rc1a/cluster-docker-laboratorio/blob/main/scripts/01-keyboard-and-update.sh"
click node_hosts_snippet "https://github.com/vg4rc1a/cluster-docker-laboratorio/blob/main/configs/hosts-snippet.txt"
click node_docker_install "https://github.com/vg4rc1a/cluster-docker-laboratorio/blob/main/scripts/03-install-docker.sh"
click node_daemon_config "https://github.com/vg4rc1a/cluster-docker-laboratorio/blob/main/configs/daemon.json"
click node_firewall_script "https://github.com/vg4rc1a/cluster-docker-laboratorio/blob/main/scripts/04-firewall.sh"
click node_init_swarm "https://github.com/vg4rc1a/cluster-docker-laboratorio/blob/main/scripts/05-init-swarm.sh"
click node_join_workers "https://github.com/vg4rc1a/cluster-docker-laboratorio/blob/main/scripts/06-join-worker.sh"
click node_labels "https://github.com/vg4rc1a/cluster-docker-laboratorio/blob/main/scripts/07-labels.sh"
click node_overlay "https://github.com/vg4rc1a/cluster-docker-laboratorio/blob/main/stacks/production-net.sh"
click node_test_service "https://github.com/vg4rc1a/cluster-docker-laboratorio/blob/main/scripts/08-test-service.sh"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_setup_docs,node_bootstrap,node_docker_install,node_daemon_config toneBlue
class node_netplan,node_network_scripts,node_hosts_snippet,node_pfsense,node_firewall_script,node_ufw toneAmber
class node_init_swarm,node_manager,node_join_workers,node_workers,node_labels,node_admin_docs toneMint
class node_overlay,node_test_service,node_nginx toneRose
```

## Components

### Host Foundation

- [Setup guidance](https://github.com/vg4rc1a/cluster-docker-laboratorio/blob/main/docs/setup.md): operator docs · Setup and recovery instructions. · `docs/setup.md`
- [OS bootstrap](https://github.com/vg4rc1a/cluster-docker-laboratorio/blob/main/scripts/01-keyboard-and-update.sh): shell script · Prepares Ubuntu hosts before cluster setup. · `scripts/01-keyboard-and-update.sh`
- [Install Docker Engine](https://github.com/vg4rc1a/cluster-docker-laboratorio/blob/main/scripts/03-install-docker.sh): shell script · Installs the Docker runtime on every node. · `scripts/03-install-docker.sh`
- [Docker daemon config](https://github.com/vg4rc1a/cluster-docker-laboratorio/blob/main/configs/daemon.json): daemon configuration · `configs/daemon.json`

### LAN and Security

- **Role Netplan configs**: Netplan YAML · Static identities: manager .101; workers .104 and .105.
- **Apply node networking**: shell scripts · Selects and applies the manager or worker Netplan configuration.
- [Shared host resolution](https://github.com/vg4rc1a/cluster-docker-laboratorio/blob/main/configs/hosts-snippet.txt): hosts snippet · `configs/hosts-snippet.txt`
- **pfSense gateway**: external firewall · LAN/WAN routing and upstream firewall boundary.
- [Apply UFW policy](https://github.com/vg4rc1a/cluster-docker-laboratorio/blob/main/scripts/04-firewall.sh): shell script · Opens SSH, HTTP(S), Swarm, gossip, and VXLAN traffic. · `scripts/04-firewall.sh`
- **Node firewall**: UFW · Host security boundary for management, published, and Swarm ports.

### Swarm Control Plane

- [Initialize manager](https://github.com/vg4rc1a/cluster-docker-laboratorio/blob/main/scripts/05-init-swarm.sh): shell script · Creates the Swarm and advertises the manager endpoint. · `scripts/05-init-swarm.sh`
- **Manager / leader**: Swarm manager · Control-plane endpoint at 192.168.1.101; administers and schedules services.
- [Join workers](https://github.com/vg4rc1a/cluster-docker-laboratorio/blob/main/scripts/06-join-worker.sh): shell script · Consumes manager address and join token. · `scripts/06-join-worker.sh`
- **Worker nodes**: Swarm workers · Two task-execution nodes at 192.168.1.104 and .105.
- [Assign node labels](https://github.com/vg4rc1a/cluster-docker-laboratorio/blob/main/scripts/07-labels.sh): shell script · Establishes placement metadata for future constraints. · `scripts/07-labels.sh`
- **Cluster operations records**: operator docs · Lifecycle commands and observed Swarm state.

### Service Validation

- [Encrypted overlay network](https://github.com/vg4rc1a/cluster-docker-laboratorio/blob/main/stacks/production-net.sh): Swarm overlay · Cross-node service network transported over VXLAN. · `stacks/production-net.sh`
- [Deploy validation service](https://github.com/vg4rc1a/cluster-docker-laboratorio/blob/main/scripts/08-test-service.sh): shell script · Deploys the Nginx workload to validate scheduling and access. · `scripts/08-test-service.sh`
- **Nginx validation workload**: Swarm service · Confirms service discovery, overlay connectivity, and published access.

## Connections

- Setup guidance → OS bootstrap: ordered procedure
- OS bootstrap → Apply node networking: prepare hosts
- Role Netplan configs → Apply node networking: role-specific inputs
- Shared host resolution → Apply node networking: hostname resolution
- Apply node networking → pfSense gateway: connects to LAN
- Apply node networking → Install Docker Engine: network ready
- Install Docker Engine → Docker daemon config: configures runtime
- Docker daemon config → Apply UFW policy: runtime ready
- Apply UFW policy → Node firewall: applies policy
- Node firewall → pfSense gateway: host and upstream boundaries
- Install Docker Engine → Initialize manager: Docker available
- Node firewall → Initialize manager: permits control traffic
- Initialize manager → Manager / leader: creates control plane
- Manager / leader → Join workers: issues join material
- Join workers → Worker nodes: attaches members
- Node firewall → Worker nodes: permits gossip and VXLAN
- Worker nodes → Assign node labels: members present
- Assign node labels → Manager / leader: placement metadata
- Manager / leader → Cluster operations records: operated and verified by
- Manager / leader → Encrypted overlay network: creates network
- Encrypted overlay network → Nginx validation workload: cross-node connectivity
- Deploy validation service → Nginx validation workload: deploys
- Manager / leader → Deploy validation service: schedules deployment
- Worker nodes → Nginx validation workload: execute tasks
