This covers deploying K3s across your VMs using Ansible. We’re using a fork of TechnoTim’s k3s-ansible repo.
Prerequisites
Install Ansible on your management machine:
Debian/Ubuntu:
sudo apt update && sudo apt install -y ansiblemacOS:
brew install ansibleClone the repo:
git clone https://github.com/meroxdotdev/k3s-ansibleConfiguration
cd k3s-ansiblecp ansible.example.cfg ansible.cfgansible-galaxy install -r ./collections/requirements.ymlcp -R inventory/sample inventory/my-clusterinventory/my-cluster/hosts.ini — set your node IPs:
[master]10.57.57.3010.57.57.3110.57.57.32
[node]10.57.57.3310.57.57.3410.57.57.35
[k3s_cluster:children]masternodeinventory/my-cluster/group_vars/all.yml — key fields to edit:
ansible_user: default VM user isubuntusystem_timezone: set to your timezone, e.g.Europe/Bucharest- Networking: comment out
#flannel_iface: eth0and usecalico_iface: "eth0"for better network policies. Flannel works too if you want something simpler. apiserver_endpoint:10.57.57.100— an unused IP on your LAN, acts as the VIP for the K3s control planek3s_token: any alphanumeric stringmetal_lb_ip_range:10.57.57.80-10.57.57.90— a range on your LAN, outside your DHCP pool, not used by anything else. This is how K3s services get exposed to your network.
Note
Make sure SSH key authentication is working between your management machine and all VMs before running the playbook.
Deploy
ansible-playbook ./site.yml -i ./inventory/my-cluster/hosts.iniOnce done, pull the kubeconfig and verify:
scp ubuntu@10.57.57.30:~/.kube/config .mkdir -p ~/.kubemv config ~/.kube/kubectl get nodesNext Steps
Proceed to the Traefik Setup guide.