This guide walks you through setting up K3s using Ansible on your Proxmox-based VMs. Ansible helps automate the process across multiple nodes, making the deployment faster and more reliable.
Prerequisites
-
Ensure Ansible is installed on your management machine (Debian/Ubuntu or macOS):
Debian/Ubuntu:
sudo apt update && sudo apt install -y ansiblemacOS:
brew install ansible-
Clone the k3s-ansible repository
We will use Techno Tim’s k3s-ansible repository, but in this guide, we’ll use a forked version:
git clone https://github.com/meroxdotdev/k3s-ansiblePre-Deployment Configuration
- Set up the Ansible environment:
cd k3s-ansible cp ansible.example.cfg ansible.cfg ansible-galaxy install -r ./collections/requirements.yml cp -R inventory/sample inventory/my-cluster-
Edit
inventory/my-cluster/hosts.iniModify this file to match your cluster’s IP addresses. Example:
[master] 10.57.57.30 10.57.57.31 10.57.57.32
[node] 10.57.57.33 10.57.57.34 10.57.57.35
[k3s_cluster:children] master node-
Edit
inventory/my-cluster/group_vars/all.ymlSome critical fields to modify:
ansible_user: Default VM user is
ubuntuwith sudo privileges.system_timezone: Set to your local timezone (e.g.,
Europe/Bucharest).Networking (
Calicovs.Flannel): Comment out#flannel_iface: eth0and usecalico_iface: "eth0"for better network policies. Flannel is the simpler alternative if you prefer an easier setup.apiserver_endpoint:
10.57.57.100- Ensure this is an unused IP in your local network. It serves as the VIP (Virtual IP) for the k3s control plane.k3s_token: Use any alphanumeric string.
metal_lb_ip_range:
10.57.57.80-10.57.57.90- The IP belongs to your local network (LAN), is not already in use by other network services, and is outside your DHCP pool range to avoid conflicts. This setup enables exposing K3s container services to your network, similar to how Docker ports are exposed to their host IP.
Note
Before running the next command, ensure SSH key authentication is set up between your management machine and all deployed VMs.
Deploy the Cluster
Run the following command to deploy the cluster:
ansible-playbook ./site.yml -i ./inventory/my-cluster/hosts.iniOnce the playbook execution completes, you can verify the cluster’s status:
# Copy the kubeconfig file from the first master node
# Move it to the correct locationmkdir -p ~/.kubemv config ~/.kube/
# Check if the cluster nodes are properly registeredkubectl get nodesIf the setup was successful, kubectl get nodes should display the cluster’s nodes and their statuses.
Next Steps
With K3s deployed, proceed to the Traefik Setup guide to configure ingress and SSL certificates for your cluster.