{"id":20150747,"url":"https://github.com/jamonation/terraform-libvirt-k8s-lab","last_synced_at":"2025-04-09T20:32:27.360Z","repository":{"id":56570309,"uuid":"307871980","full_name":"jamonation/terraform-libvirt-k8s-lab","owner":"jamonation","description":"A project to build nodes for a Kubernetes cluster using Terraform and the libvirt provider, and set up and configure Kubernetes on them using Ansible","archived":false,"fork":false,"pushed_at":"2022-12-09T02:56:24.000Z","size":86,"stargazers_count":15,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-23T22:25:29.914Z","etag":null,"topics":["ansible","hacktoberfest","kubernetes","kubernetes-labs","lab","terraform","terraform-libvirt-provider"],"latest_commit_sha":null,"homepage":"","language":"HCL","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jamonation.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-10-28T01:19:59.000Z","updated_at":"2025-02-07T20:39:23.000Z","dependencies_parsed_at":"2023-01-25T16:30:15.615Z","dependency_job_id":null,"html_url":"https://github.com/jamonation/terraform-libvirt-k8s-lab","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamonation%2Fterraform-libvirt-k8s-lab","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamonation%2Fterraform-libvirt-k8s-lab/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamonation%2Fterraform-libvirt-k8s-lab/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jamonation%2Fterraform-libvirt-k8s-lab/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jamonation","download_url":"https://codeload.github.com/jamonation/terraform-libvirt-k8s-lab/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248107428,"owners_count":21048931,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansible","hacktoberfest","kubernetes","kubernetes-labs","lab","terraform","terraform-libvirt-provider"],"created_at":"2024-11-13T22:53:15.620Z","updated_at":"2025-04-09T20:32:27.339Z","avatar_url":"https://github.com/jamonation.png","language":"HCL","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Terraform + libvirt + Ansible = HA Kubernetes Lab\n\n![Image](https://raw.githubusercontent.com/jamonation/terraform-libvirt-k8s-lab/assets/terraform-libvirt-k8s-lab.png)\n\n## Introduction\n\nA home lab is a great way to explore and learn about different tools, architectures, and development methods.\n\nThe idea behind this repository is to use Terraform and Ansible to build a local Kubernetes cluster that is more extensible, and closer to a production architecture than many of the typical single-machine example environments.\n\n## About\n\nThis repository contains all the Terraform modules and Ansible roles that you need to build a local [High Availability Kubernetes cluster](https://kubernetes.io/docs/setup/production-environment/tools/kubeadm/ha-topology/) that you can experiment with.\n\nThe Terraform modules use the [`libvirt` terraform provider](https://github.com/dmacvicar/terraform-provider-libvirt) to provision a virtual network and virtual machines, so you'll need to be running `libvirtd` on Linux to be able to use this repository.\n\nThe stacked Kubernetes control plane is managed using [HAProxy and Keepalived]([https://github.com/kubernetes/kubeadm/blob/master/docs/ha-considerations.md#keepalived-and-haproxy) running as static pods on the control plane VMs.\n\n## Requirements\n\nTo use this repository you will need the following on your local machine:\n\n* Linux\n* Ansible\n* Terraform \u003e= v0.13\n* libvirt with a `default` storage pool - the [`network module`](https://github.com/jamonation/terraform-libvirt-k8s-lab/tree/main/terraform/modules/network) in this repository will define a network for you\n* [terraform-provider-libvirt](https://github.com/dmacvicar/terraform-provider-libvirt)\n* Enough CPU, RAM, and disk space to run two libvirt guests - the more the better!\n\n## Using this repository\n\n**Before using terraform** add your **public*** key, excluding the `ssh-rsa` prefix in the various `variables.tf` files corresponding sections:\n\n```\nvariable \"ssh-public-key\" {\n  description = \"ssh-rsa key for terraform-libvirt user\"\n  default     = \"\u003cKEY GOES HERE\u003e\"\n}\n```\n\nRunning `terraform apply` with no variable arguments will create 5 Kubernetes nodes - 3 control plane, and 2 nodes for workloads. Each will use 2 CPUs, and have 2GB of RAM allocated.\n\n**Before using ansible** you need to add the following to your `~/.ssh/config` to avoid having fingerprint check botch your ansible configuration:\n\n```\nHost 10.17.3.*\n  StrictHostKeyChecking no\n```\n\nOnce the VMs are up, running `ansible-playbook -i hosts bootstrap.yaml` in the `ansible` directory will bootstrap the Kubernetes control plane on one VM. The role will also generate a token for other `control-plane` nodes and will use that on the remaining nodes to join them to the cluster.\n\nKubernetes is accessed using a virtual IP that is managed by HAProxy and Keepalived. The IP address is `10.17.3.254`.\n\nRunning `ansible-playbook -i hosts local-config.yaml` will copy `admin.conf` to the playbook directory to be used along with `kubectl` as `kubectl --kubeconfig admin.conf get namespace`.\n\nEach of the VMs has a static IP address for ease of access and keeping track of what lives where. The machines (in the default configuration) are:\n\n```\nk8s-controller-2 10.17.3.2\nk8s-controller-3 10.17.3.3\nk8s-controller-4 10.17.3.4\n\nk8s-nodes-2 10.17.3.10\nk8s-nodes-3 10.17.3.11\n```\n\nThe guest hostname are indexed roughly according to their IP address - since 10.17.3.1 is the gateway, the nodes and IPs start at `2`.\n\n**Todo: fix the k8s-nodes indexing to use an offset of 10.**\n\n## Helpful resources, kudos, and credits\n\n[How To Provision VMs on KVM with Terraform](https://computingforgeeks.com/how-to-provision-vms-on-kvm-with-terraform/) - a great resource to consult if you're just getting started with Terraform and KVM.\n\n[Using the Libvirt Provisioner With Terraform for KVM](https://blog.ruanbekker.com/blog/2020/10/08/using-the-libvirt-provisioner-with-terraform-for-kvm/) - a more advanced example than the first\n\n[\nDynamic Cloud-Init Content with Terraform File Templates\n](https://grantorchard.com/dynamic-cloudinit-content-with-terraform-file-templates/) - templating `cloud-init` data wouldn't have been possible without this invaluable explanation.\n\nThe [`terraform-provider-libvirt` documentation](https://github.com/dmacvicar/terraform-provider-libvirt) of course!\n\n[How To Create a Kubernetes Cluster Using Kubeadm on Ubuntu 18.04](https://www.digitalocean.com/community/tutorials/how-to-create-a-kubernetes-cluster-using-kubeadm-on-ubuntu-18-04) - this tutorial formed the basis for the Ansible roles\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamonation%2Fterraform-libvirt-k8s-lab","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjamonation%2Fterraform-libvirt-k8s-lab","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjamonation%2Fterraform-libvirt-k8s-lab/lists"}