How vg4rc1a/cluster-docker-laboratorio works
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: 03-install-docker.sh Install Docker Engine · 05-init-swarm.sh Initialize manager · 01-keyboard-and-update.sh OS bootstrap · daemon.json Docker daemon config
Components 19
Host Foundation
- Setup guidance · Setup and recovery instructions.
docs/setup.md - OS bootstrap · Prepares Ubuntu hosts before cluster setup.
scripts/01-keyboard-and-update.sh - Install Docker Engine · Installs the Docker runtime on every node.
scripts/03-install-docker.sh - Docker daemon config
configs/daemon.json
LAN and Security
- Role Netplan configs · Static identities: manager .101; workers .104 and .105.
- Apply node networking · Selects and applies the manager or worker Netplan configuration.
- Shared host resolution
configs/hosts-snippet.txt - pfSense gateway · LAN/WAN routing and upstream firewall boundary.
- Apply UFW policy · Opens SSH, HTTP(S), Swarm, gossip, and VXLAN traffic.
scripts/04-firewall.sh - Node firewall · Host security boundary for management, published, and Swarm ports.
Swarm Control Plane
- Initialize manager · Creates the Swarm and advertises the manager endpoint.
scripts/05-init-swarm.sh - Manager / leader · Control-plane endpoint at 192.168.1.101; administers and schedules services.
- Join workers · Consumes manager address and join token.
scripts/06-join-worker.sh - Worker nodes · Two task-execution nodes at 192.168.1.104 and .105.
- Assign node labels · Establishes placement metadata for future constraints.
scripts/07-labels.sh - Cluster operations records · Lifecycle commands and observed Swarm state.
Service Validation
- Encrypted overlay network · Cross-node service network transported over VXLAN.
stacks/production-net.sh - Deploy validation service · Deploys the Nginx workload to validate scheduling and access.
scripts/08-test-service.sh - Nginx validation workload · Confirms service discovery, overlay connectivity, and published access.
Connections 24
- 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