This repository provides a simple way to set up a Kubernetes K3S cluster using Vagrant-libvirt. It is designed for developers and system administrators who want to quickly create a local Kubernetes K3S environment for testing, learning, or development purposes without the need for complex cloud infrastructure.
- Easy Setup: With just a command you have a simple K3S cluster.
- Customization Options: There are separated varibles to edit in the vagrant file to change number of workers, cpu and ram.
- Export kube config: The start command copies the kube config file to the local machine that allows local connection using kubctl.
- Docker Registry: It contains a local docker registry to push your images to the cluster.
Before you begin, ensure your system meets the following prerequisites:
- Git - For version control
- Vagrant - Virtual machine management tool
- Kubectl - To manage the cluster locally outside vm.
- Libvirt manager - Libvirt virtual machine manager
- Hypervisor - Supported Hypervisor like kvm/QEMU
- (Optional)OpenLens - Gui for managing and troubleshooting Kubernetes.
Follow these steps to set up the Kubernetes K3S cluster:
- Clone the Repository: Use the following command to clone the repository:
git clone https://github.com/fungame2270/kubernetes-K3S-vagrant-libvirt.git- Start the Cluster: Navigate to the cloned repository folder (where the
Scriptsare located "start.sh" and "destroy.sh") and execute thestart.sh:
cd kubernetes-K3S-vagrant-libvirt
./start.sh- Tag and push a image: you can push images into to the registry from the host
docker tag busybox registry.localhost/busybox
docker push registry.localhost/busybox- Destroy the Cluster: Simply run the
destroy.shit will stop the vms and delete the config file and join cluster file:
./destroy.shNote
The script will ask for sudo permission to change the kube config ownership and permissions. Vagrant will ask too because of NFS for start.sh and destroy.sh.
To increase the number of worker nodes or adjust CPU and RAM, change the NodeCount,CPU and Memory for the master and workers in the variables inside the Vagrantfile:
Vagrant.configure(2) do |config|
...
NodeCount = 1
MasterCpu = 4
MasterMemory = 4096
WorkerCpu = 2
WorkerMemory = 4096
...- This repository is a derivative work based on hfmartinez/kubernetes-vagrant
- Documentation used K3S docs
This project is licensed under the MIT License - see the LICENSE file for details.