This repository provides a fully automated setup for a highly available Kubernetes (K8s) environment using Vagrant and Kubespray. It provisions a Kubernetes cluster with multiple master nodes, a load balancer, and worker nodes using VirtualBox as the provider and Ubuntu 22.04.3 "Jammy Jellyfish" as the base OS. This setup is intended for development and testing purposes.
Before you begin, ensure your system meets the following requirements:
- Ubuntu-based operating system with at least 8 CPU cores and 16GB RAM.
- Essential applications: VirtualBox and Vagrant.
To run this script on an Ubuntu-based operating system:
-
Open a terminal.
-
Update your package index:
sudo apt update
-
Install VirtualBox:
sudo apt install virtualbox
-
Download and install Vagrant from the official website or using the following command:
sudo apt install vagrant
For other operating systems, refer to the official Vagrant documentation for installation instructions.
-
Clone this repository to your local machine:
git clone https://github.com/tadbiri/HA-Kuber-kubespray-vagrant.git
-
Navigate to the directory containing the Vagrantfile:
cd HA-Kuber-kubespray-vagrant
-
Edit the
control.rb
file to adjust the number of nodes, CPU, memory, and IP configurations as needed. -
Run the following command to start the VMs and provision the Kubernetes cluster:
vagrant up
-
Once the provisioning is complete, log into the load balancer node:
vagrant ssh kube-lb-1
-
Run the post setup script to complete the cluster setup:
sudo /root/post_setup.sh
Here are some useful Vagrant commands to manage your VMs:
-
Halt all running VMs:
vagrant halt
-
Reload all VMs (useful after changing the Vagrantfile):
vagrant reload
-
Destroy all VMs:
vagrant destroy -f
-
SSH into a specific VM:
vagrant ssh <vm_name>
-
Check the status of VMs:
vagrant status
The Vagrantfile
defines the configuration for creating and provisioning the virtual machines. It sets up master nodes, worker nodes, and load balancers, and configures their CPU, memory, and network settings.
The control.rb
file contains variables to control the number of master, worker, and load balancer nodes, as well as their CPU, memory, and IP configurations.
The bootstrap.sh
script is executed during the provisioning phase of each VM. It installs essential packages, enables root login, and sets up SSH keys for secure communication between nodes.
The post_setup.sh
script performs additional configuration after the initial setup. It installs necessary packages, configures HAProxy, clones the Kubespray repository, and runs Ansible playbooks to set up the Kubernetes cluster. This script must be run manually on the load balancer node after the VMs are up.
For more detailed descriptions and usage instructions of each script, refer to the respective README files in this repository.
- This setup is intended for development and testing purposes only and may not be suitable for production environments.
- Ensure that your system meets the hardware requirements specified in the control file to avoid performance issues.
- Internet access is enabled by default for all VMs to facilitate package installation and updates.
For further details on each script and its functionality, refer to the individual README files linked below:
By following the instructions and utilizing the provided scripts, you can efficiently set up a fully automated HA Kubernetes environment for your development and testing needs.
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.
For any questions or issues, please open a GitHub issue in this repository.