|
1 | | -# vagrant |
| 1 | +# Vagrant Kubernetes Cluster |
| 2 | + |
| 3 | +[](https://opensource.org/licenses/MIT) |
| 4 | +[](https://www.vagrantup.com/) |
| 5 | +[](https://kubernetes.io/) |
| 6 | +[](https://ubuntu.com/) |
| 7 | + |
| 8 | +This project sets up a local Kubernetes cluster using Vagrant and VirtualBox. It creates two Ubuntu 22.04 virtual machines: one master node and one worker node with automatic installation of Docker, Kubernetes components, and necessary configurations. |
| 9 | + |
| 10 | +## Architecture |
| 11 | + |
| 12 | +```mermaid |
| 13 | +graph TB |
| 14 | + subgraph Vagrant-Managed Environment |
| 15 | + subgraph Master Node |
| 16 | + A[Control Plane] --> B[API Server] |
| 17 | + B --> C[etcd] |
| 18 | + B --> D[Controller Manager] |
| 19 | + B --> E[Scheduler] |
| 20 | + end |
| 21 | + subgraph Worker Node |
| 22 | + F[kubelet] --> G[Container Runtime] |
| 23 | + H[kube-proxy] --> G |
| 24 | + end |
| 25 | + B <-.-> F |
| 26 | + B <-.-> H |
| 27 | + end |
| 28 | + style Master Node fill:#f9f,stroke:#333,stroke-width:2px |
| 29 | + style Worker Node fill:#bbf,stroke:#333,stroke-width:2px |
| 30 | +``` |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | +## Prerequisites |
| 35 | + |
| 36 | +- [VirtualBox](https://www.virtualbox.org/wiki/Downloads) |
| 37 | +- [Vagrant](https://www.vagrantup.com/downloads) |
| 38 | +- At least 4GB of RAM available |
| 39 | +- At least 20GB of free disk space |
| 40 | + |
| 41 | +## ✨ Features |
| 42 | + |
| 43 | +<table> |
| 44 | +<tr> |
| 45 | + <td align="center">🔄</td> |
| 46 | + <td>Automated VM provisioning with Ubuntu 22.04</td> |
| 47 | +</tr> |
| 48 | +<tr> |
| 49 | + <td align="center">🌐</td> |
| 50 | + <td>Pre-configured network settings</td> |
| 51 | +</tr> |
| 52 | +<tr> |
| 53 | + <td align="center">🐳</td> |
| 54 | + <td>Automatic installation of Docker and Kubernetes components</td> |
| 55 | +</tr> |
| 56 | +<tr> |
| 57 | + <td align="center">🚀</td> |
| 58 | + <td>Ready-to-use Kubernetes cluster setup</td> |
| 59 | +</tr> |
| 60 | +<tr> |
| 61 | + <td align="center">🔒</td> |
| 62 | + <td>Secure communication between nodes</td> |
| 63 | +</tr> |
| 64 | +<tr> |
| 65 | + <td align="center">🔍</td> |
| 66 | + <td>Easy monitoring and management</td> |
| 67 | +</tr> |
| 68 | +</table> |
| 69 | + |
| 70 | +## 🖥 Cluster Configuration |
| 71 | + |
| 72 | +> **Note about IP Addressing**: This configuration uses `192.168.63.1` and `192.168.63.2` for the master and worker nodes respectively. You can modify these IPs in the `Vagrantfile` to use any IP addresses from your router's IP range that are outside the DHCP scope. Make sure to choose IPs that won't conflict with other devices on your network. |
| 73 | +
|
| 74 | +<table> |
| 75 | +<tr> |
| 76 | + <th width="50%">Master Node</th> |
| 77 | + <th width="50%">Worker Node</th> |
| 78 | +</tr> |
| 79 | +<tr> |
| 80 | +<td> |
| 81 | + |
| 82 | +```yaml |
| 83 | +IP: 192.168.63.1 |
| 84 | +Hostname: master |
| 85 | +Memory: 2048MB |
| 86 | +CPUs: 2 |
| 87 | +Role: Control Plane |
| 88 | +``` |
| 89 | +
|
| 90 | +</td> |
| 91 | +<td> |
| 92 | +
|
| 93 | +```yaml |
| 94 | +IP: 192.168.63.2 |
| 95 | +Hostname: worker |
| 96 | +Memory: 2048MB |
| 97 | +CPUs: 2 |
| 98 | +Role: Worker |
| 99 | +``` |
| 100 | +
|
| 101 | +</td> |
| 102 | +</tr> |
| 103 | +</table> |
| 104 | +
|
| 105 | + |
| 106 | +
|
| 107 | +## Quick Start |
| 108 | +
|
| 109 | +> **💡 Tip**: Before starting, you may want to adjust the IP addresses in the `Vagrantfile` if the default IPs (`192.168.63.1, 192.168.63.2`) conflict with your network setup. Edit the `private_network` IP settings in the Vagrantfile to match your network requirements. |
| 110 | + |
| 111 | +1. Clone this repository: |
| 112 | +```bash |
| 113 | +git clone <repository-url> |
| 114 | +cd vagrant |
| 115 | +``` |
| 116 | + |
| 117 | +2. Start the cluster: |
| 118 | +```bash |
| 119 | +vagrant up |
| 120 | +``` |
| 121 | + |
| 122 | +3. SSH into the master node: |
| 123 | +```bash |
| 124 | +vagrant ssh master |
| 125 | +``` |
| 126 | + |
| 127 | +4. SSH into the worker node: |
| 128 | +```bash |
| 129 | +vagrant ssh worker |
| 130 | +``` |
| 131 | + |
| 132 | +5. Stop the cluster: |
| 133 | +```bash |
| 134 | +vagrant halt |
| 135 | +``` |
| 136 | + |
| 137 | +6. Destroy the cluster: |
| 138 | +```bash |
| 139 | +vagrant destroy |
| 140 | +``` |
| 141 | + |
| 142 | +## 🛠 Components Installed |
| 143 | + |
| 144 | +<details> |
| 145 | +<summary>Click to expand installed components</summary> |
| 146 | + |
| 147 | +| Component | Version | Description | |
| 148 | +|-----------|---------|-------------| |
| 149 | +| Docker CE | Latest | Container runtime engine | |
| 150 | +| kubelet | Latest | Node agent | |
| 151 | +| kubeadm | Latest | Cluster bootstrapping tool | |
| 152 | +| kubectl | Latest | Command-line interface | |
| 153 | +| containerd | Latest | Container runtime | |
| 154 | +| Weave CNI | v2.8.1 | Container Network Interface | |
| 155 | + |
| 156 | +</details> |
| 157 | + |
| 158 | +## Cluster Setup Instructions |
| 159 | + |
| 160 | +After the VMs are up and running, follow these steps to initialize your Kubernetes cluster: |
| 161 | + |
| 162 | +### 1. On Master Node |
| 163 | + |
| 164 | +First, log into the master node: |
| 165 | +```bash |
| 166 | +vagrant ssh master |
| 167 | +``` |
| 168 | + |
| 169 | +Pull required Kubernetes images: |
| 170 | +```bash |
| 171 | +sudo kubeadm config images pull |
| 172 | +``` |
| 173 | + |
| 174 | +Initialize the cluster: |
| 175 | +```bash |
| 176 | +sudo kubeadm init --pod-network-cidr=10.201.0.0/16 --apiserver-advertise-address=192.168.63.1 |
| 177 | +``` |
| 178 | + |
| 179 | +### 2. Install CNI (Container Network Interface) |
| 180 | + |
| 181 | +After the cluster initialization, install Weave CNI: |
| 182 | +```bash |
| 183 | +kubectl apply -f https://github.com/weaveworks/weave/releases/download/v2.8.1/weave-daemonset-k8s.yaml |
| 184 | +``` |
| 185 | + |
| 186 | +### 3. Join Worker Node |
| 187 | + |
| 188 | +Copy the `kubeadm join` command from the master node's initialization output and run it on the worker node with sudo privileges. |
| 189 | + |
| 190 | +### 4. Verify Cluster Status |
| 191 | + |
| 192 | +After joining the worker node, verify the cluster status from the master node: |
| 193 | + |
| 194 | +```bash |
| 195 | +# Check node status |
| 196 | +kubectl get nodes |
| 197 | +``` |
| 198 | + |
| 199 | +Expected output (it may take a few minutes for the nodes to be ready): |
| 200 | +``` |
| 201 | +NAME STATUS ROLES AGE VERSION |
| 202 | +master Ready control-plane 5m32s v1.30.x |
| 203 | +worker Ready <none> 2m14s v1.30.x |
| 204 | +``` |
| 205 | + |
| 206 | +> **Note**: The nodes may show `NotReady` status initially as the CNI (Container Network Interface) is being configured. Please wait a few minutes for the status to change to `Ready`. |
| 207 | + |
| 208 | +### Troubleshooting |
| 209 | + |
| 210 | +If you encounter issues while joining the worker node, try these steps on both nodes: |
| 211 | + |
| 212 | +1. Reset the cluster configuration: |
| 213 | +```bash |
| 214 | +sudo kubeadm reset |
| 215 | +``` |
| 216 | + |
| 217 | +2. Perform system cleanup: |
| 218 | +```bash |
| 219 | +sudo swapoff -a |
| 220 | +sudo systemctl restart kubelet |
| 221 | +sudo iptables -F |
| 222 | +sudo rm -rf /var/lib/cni/ |
| 223 | +sudo systemctl restart containerd |
| 224 | +sudo systemctl daemon-reload |
| 225 | +``` |
| 226 | + |
| 227 | +3. After cleanup, retry the cluster initialization on master and join command on worker. |
| 228 | + |
| 229 | +## Default Credentials |
| 230 | + |
| 231 | +- Username: vagrant |
| 232 | +- Password: vagrant |
| 233 | + |
| 234 | +## License |
| 235 | + |
| 236 | +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. |
| 237 | + |
| 238 | +Copyright (c) 2024 Vagrant Kubernetes Cluster |
| 239 | + |
| 240 | +## 📫 Support & Contribution |
| 241 | + |
| 242 | +If you encounter any issues or need assistance: |
| 243 | + |
| 244 | +[](https://github.com/yourusername/vagrant-kubernetes/issues/new) |
| 245 | +[](https://github.com/yourusername/vagrant-kubernetes/pulls) |
| 246 | + |
| 247 | +## 📝 License |
| 248 | + |
| 249 | +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. |
| 250 | + |
| 251 | +--- |
| 252 | + |
| 253 | +<div align="center"> |
| 254 | +Made with ❤️ for the Kubernetes community |
| 255 | +</div> |
0 commit comments