This repo provides code for an automated way of deploying a K8S cluster with Ansible on KVM hypervisor. The project can be divided in three phases. First, cloud image is downloaded and customized accordingly using libguestfs popular tool virt-customize. Second, using the libvirt module and XML definition files, VMs were started on KVM hypervisor. And third, initialization scripts on each VM were run to deploy the K8S cluster. A medium story with more detailed discussion is here. --> https://medium.com/@emrah-t/kubernetes-cluster-up-and-running-in-seconds-with-ansible-devops-diaries-757374284f32
- A Linux computer (VM or physical) with the required KVM/libvirt components installed (kvmhost). --> https://linuxhint.com/install-kvm-ubuntu-22-04/
- Ansible binaries installed on the controller machine. --> https://docs.ansible.com/ansible/latest/installation_guide/installation_distros.html
- An intermediate level of domain (Ansible, KVM/libvirt, Kubernetes) knowledge.
- Ansible roles were employed to keep tasks simpler and more organized.
- The Ubuntu 20.04 cloud image is downloaded and customized accordingly using virt-customize.
- As for customization, configuration files (under kvmhost_scripts directory) and SSH keys were copied, root passwords were set.
- community.libvirt.virt module was used to manage KVM VMs.
- XML definition files under templates directory were used to boot up the VMs.
- Four VMs were defined (HAProxy Load Balancer, master and two workers).
- After starting the VMs, initialization scripts (under kvmhost_scripts directory) were run to bootstrap K8S cluster.
- Resulting topology is given below.
- Clone the repo.
- Go to directory playbook.yml stands and run "ansible-playbook playbook.yml -i inventory/hypervisors.yml"
- Follow the creation of VMs via virsh or Virtual Machine Manager. After seeing they're up, connect with console or SSH and follow logs in /tmp/init.log (screencast below).
- Final check with "kubectl get nodes" on the master node (screencast below). All bootstrapping lasts around 350 seconds on my home hardware.