Create a Kubernetes cluster based on Rancher's k3s project with distinct hosts for the control plane and worker nodes on a bare metal machine running Linux and libvirt + qemu/kvm.
- A bare metal machine with
- at least 16GB memory (for 1 master, 2 worker nodes), 32GB recommended)
- a CPU with at least 4 physical cores
- with any Linux distro (this guide assumes Ubuntu 18.04)
- Install libvirt, qemu/kvm. E.g., on Ubuntu:
apt-get install -qy qemu-kvm libvirt-bin virtinst python3 vagrant
- Start the libvirt daemon. Using either virsh or virt-manager, create a virtual network:
virsh -c qemu:///system net-create libvirt/default_network.xml
- Install the
vagrant-libvirt
plugin:vagrant plugin install vagrant-libvirt
- Initialize and install the virtualenv:
python -m venv venv pip install -r requirements.txt
./generate_inventory_local.sh
ansible-playbook -i hosts_vagrant.ini create-k3s-cluster.yml
- Install
kubectl
on the local machine - Configure it
mkdir -p ~/.kube && vagrant ssh master01 -c 'sudo cat .kube/config' > ~/.kube/config
- Run
kubectl
# kubectl cluster-info Kubernetes master is running at https://192.168.122.127:6443 CoreDNS is running at https://192.168.122.127:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy Metrics-server is running at https://192.168.122.127:6443/api/v1/namespaces/kube-system/services/https:metrics-server:/proxy To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'. # kubectl get nodes NAME STATUS ROLES AGE VERSION master Ready master 149m v1.19.3+k3s2 worker-3 Ready <none> 139m v1.19.3+k3s2 worker-2 Ready <none> 139m v1.19.3+k3s2 worker-1 Ready <none> 139m v1.19.3+k3s2