|
| 1 | +# SwarmCracker Cluster Automation |
| 2 | + |
| 3 | +Ansible playbooks and roles for automated SwarmCracker cluster deployment. |
| 4 | + |
| 5 | +## Directory Structure |
| 6 | + |
| 7 | +``` |
| 8 | +infrastructure/ansible/ |
| 9 | +├── ansible.cfg # Ansible configuration |
| 10 | +├── inventory/ # Cluster inventory |
| 11 | +│ ├── production/ # Production cluster |
| 12 | +│ └── staging/ # Staging cluster |
| 13 | +├── group_vars/ # Group variables |
| 14 | +│ ├── all.yml # Variables for all hosts |
| 15 | +│ ├── managers.yml # Manager-specific variables |
| 16 | +│ └── workers.yml # Worker-specific variables |
| 17 | +├── host_vars/ # Host-specific variables |
| 18 | +├── roles/ # Ansible roles |
| 19 | +│ ├── common/ # Common setup (prerequisites) |
| 20 | +│ ├── manager/ # SwarmCracker manager setup |
| 21 | +│ └── worker/ # SwarmCracker worker setup |
| 22 | +├── site.yml # Main playbook |
| 23 | +├── setup-manager.yml # Manager-only playbook |
| 24 | +└── setup-worker.yml # Worker-only playbook |
| 25 | +``` |
| 26 | + |
| 27 | +## Quick Start |
| 28 | + |
| 29 | +### 1. Configure Inventory |
| 30 | + |
| 31 | +Edit `inventory/production/hosts`: |
| 32 | + |
| 33 | +```ini |
| 34 | +[managers] |
| 35 | +manager1 ansible_host=192.168.1.10 |
| 36 | + |
| 37 | +[workers] |
| 38 | +worker1 ansible_host=192.168.1.11 |
| 39 | +worker2 ansible_host=192.168.1.12 |
| 40 | + |
| 41 | +[swarmcracker:children] |
| 42 | +managers |
| 43 | +workers |
| 44 | +``` |
| 45 | + |
| 46 | +### 2. Configure Variables |
| 47 | + |
| 48 | +Edit `group_vars/all.yml`: |
| 49 | + |
| 50 | +```yaml |
| 51 | +swarmcracker_version: "v0.2.0" |
| 52 | +swarmcracker_arch: "amd64" # or "arm64" |
| 53 | +swarmcracker_download_url: "https://github.com/restuhaqza/SwarmCracker/releases/download/{{ swarmcracker_version }}" |
| 54 | +``` |
| 55 | +
|
| 56 | +### 3. Deploy Cluster |
| 57 | +
|
| 58 | +```bash |
| 59 | +# Deploy entire cluster (managers + workers) |
| 60 | +ansible-playbook -i inventory/production site.yml |
| 61 | + |
| 62 | +# Deploy managers only |
| 63 | +ansible-playbook -i inventory/production setup-manager.yml |
| 64 | + |
| 65 | +# Deploy workers only |
| 66 | +ansible-playbook -i inventory/production setup-worker.yml --extra-vars "manager_host=192.168.1.10" |
| 67 | + |
| 68 | +# Deploy with custom variables |
| 69 | +ansible-playbook -i inventory/production site.yml \ |
| 70 | + --extra-vars "swarmcracker_version=v0.2.0" |
| 71 | +``` |
| 72 | + |
| 73 | +### 4. Verify Deployment |
| 74 | + |
| 75 | +```bash |
| 76 | +# Check manager status |
| 77 | +ansible managers -i inventory/production -m command -a "swarmctl node ls" |
| 78 | + |
| 79 | +# Check worker status |
| 80 | +ansible workers -i inventory/production -m command -a "systemctl status swarmd-firecracker" |
| 81 | +``` |
| 82 | + |
| 83 | +## Requirements |
| 84 | + |
| 85 | +- Ansible 2.9+ |
| 86 | +- Python 3.8+ on control node |
| 87 | +- SSH access to target hosts |
| 88 | +- Target hosts: Ubuntu 20.04+/Debian 11+/CentOS 8+ |
| 89 | + |
| 90 | +## Roles |
| 91 | + |
| 92 | +### common |
| 93 | +- Install system dependencies (Go, Firecracker, etc.) |
| 94 | +- Configure kernel modules (KVM, VXLAN) |
| 95 | +- Setup network bridges |
| 96 | +- Configure firewall rules |
| 97 | + |
| 98 | +### manager |
| 99 | +- Download and install SwarmCracker binaries |
| 100 | +- Initialize SwarmKit manager |
| 101 | +- Configure manager service |
| 102 | +- Generate worker join tokens |
| 103 | + |
| 104 | +### worker |
| 105 | +- Download and install SwarmCracker binaries |
| 106 | +- Join SwarmKit cluster |
| 107 | +- Configure worker service |
| 108 | +- Setup VXLAN networking |
| 109 | + |
| 110 | +## Variables |
| 111 | + |
| 112 | +| Variable | Default | Description | |
| 113 | +|----------|---------|-------------| |
| 114 | +| `swarmcracker_version` | `v0.2.0` | SwarmCracker release version | |
| 115 | +| `swarmcracker_arch` | `amd64` | Architecture (amd64/arm64) | |
| 116 | +| `swarmcracker_install_dir` | `/usr/local/bin` | Binary installation directory | |
| 117 | +| `swarmcracker_state_dir` | `/var/lib/swarmcracker` | State directory | |
| 118 | +| `swarmcracker_kernel_path` | `/usr/share/firecracker/vmlinux` | Firecracker kernel path | |
| 119 | +| `swarmcracker_rootfs_dir` | `/var/lib/firecracker/rootfs` | Rootfs directory | |
| 120 | +| `swarmcracker_bridge_name` | `swarm-br0` | Network bridge name | |
| 121 | +| `swarmcracker_subnet` | `192.168.127.0/24` | VM subnet | |
| 122 | +| `swarmcracker_bridge_ip` | `192.168.127.1/24` | Bridge IP | |
| 123 | +| `swarmcracker_vxlan_enabled` | `true` | Enable VXLAN networking | |
| 124 | +| `swarmcracker_vxlan_vni` | `100` | VXLAN VNI | |
| 125 | +| `swarmcracker_vxlan_port` | `4789` | VXLAN UDP port | |
| 126 | + |
| 127 | +## Examples |
| 128 | + |
| 129 | +### Single Node (Development) |
| 130 | + |
| 131 | +```ini |
| 132 | +[managers] |
| 133 | +localhost ansible_connection=local |
| 134 | + |
| 135 | +[workers] |
| 136 | + |
| 137 | +[swarmcracker:children] |
| 138 | +managers |
| 139 | +``` |
| 140 | + |
| 141 | +### Multi-Node Production |
| 142 | + |
| 143 | +```ini |
| 144 | +[managers] |
| 145 | +manager1 ansible_host=192.168.1.10 |
| 146 | +manager2 ansible_host=192.168.1.11 |
| 147 | +manager3 ansible_host=192.168.1.12 |
| 148 | + |
| 149 | +[workers] |
| 150 | +worker1 ansible_host=192.168.1.20 |
| 151 | +worker2 ansible_host=192.168.1.21 |
| 152 | +worker3 ansible_host=192.168.1.22 |
| 153 | +worker4 ansible_host=192.168.1.23 |
| 154 | +worker5 ansible_host=192.168.1.24 |
| 155 | + |
| 156 | +[swarmcracker:children] |
| 157 | +managers |
| 158 | +workers |
| 159 | +``` |
| 160 | + |
| 161 | +### Mixed Architecture |
| 162 | + |
| 163 | +```ini |
| 164 | +[managers] |
| 165 | +manager1 ansible_host=192.168.1.10 swarmcracker_arch=amd64 |
| 166 | + |
| 167 | +[workers] |
| 168 | +worker1 ansible_host=192.168.1.11 swarmcracker_arch=amd64 |
| 169 | +worker2 ansible_host=192.168.1.12 swarmcracker_arch=arm64 # ARM server |
| 170 | +``` |
| 171 | + |
| 172 | +## Troubleshooting |
| 173 | + |
| 174 | +### Check Ansible Connection |
| 175 | + |
| 176 | +```bash |
| 177 | +ansible all -i inventory/production -m ping |
| 178 | +``` |
| 179 | + |
| 180 | +### Verbose Output |
| 181 | + |
| 182 | +```bash |
| 183 | +ansible-playbook -i inventory/production site.yml -vvv |
| 184 | +``` |
| 185 | + |
| 186 | +### Dry Run |
| 187 | + |
| 188 | +```bash |
| 189 | +ansible-playbook -i inventory/production site.yml --check --diff |
| 190 | +``` |
| 191 | + |
| 192 | +### Cleanup |
| 193 | + |
| 194 | +```bash |
| 195 | +ansible-playbook -i inventory/production teardown.yml |
| 196 | +``` |
| 197 | + |
| 198 | +## See Also |
| 199 | + |
| 200 | +- [SwarmCracker Installation Guide](../../docs/getting-started/installation-guide.md) |
| 201 | +- [SwarmCracker Documentation](../../docs/) |
| 202 | +- [Ansible Documentation](https://docs.ansible.com/) |
0 commit comments