Ansible playbooks to deploy a K3s Kubernetes cluster with Cilium CNI on Linux VMs.
- Lightweight Kubernetes (K3s) installation
- Cilium CNI with eBPF dataplane
- Hubble observability (UI and Relay)
- kube-proxy replacement via Cilium
- Multi-node cluster support
- Ansible 2.12+
- Python 3.8+
- Ubuntu 22.04 / Debian 12 (recommended)
- 2+ vCPUs, 2GB+ RAM per node
- SSH key-based authentication
- Sudo privileges
pip install ansible
ansible-galaxy collection install -r requirements.ymlEdit inventory/hosts.ini with your VM details:
[k3s_server]
server1 ansible_host=192.168.1.10
[k3s_agents]
agent1 ansible_host=192.168.1.11
agent2 ansible_host=192.168.1.12
[all:vars]
ansible_user=ubuntu
ansible_ssh_private_key_file=~/.ssh/id_rsaEdit group_vars/all.yml to adjust versions and settings.
# Test connectivity first
ansible all -m ping
# Deploy the cluster
ansible-playbook site.ymlAfter deployment, the kubeconfig is saved to ./kubeconfig:
export KUBECONFIG=$(pwd)/kubeconfig
kubectl get nodes
kubectl -n kube-system get pods| Playbook | Description |
|---|---|
site.yml |
Full cluster deployment |
reset.yml |
Completely remove K3s from all nodes |
| Role | Description |
|---|---|
prereqs |
System preparation (packages, kernel modules, sysctl) |
k3s-server |
K3s control plane installation |
k3s-agent |
K3s worker node installation |
cilium |
Cilium CNI installation via Helm |
After deployment, verify Cilium status:
# Check Cilium pods
kubectl -n kube-system get pods -l app.kubernetes.io/part-of=cilium
# Install Cilium CLI (optional)
CILIUM_CLI_VERSION=$(curl -s https://raw.githubusercontent.com/cilium/cilium-cli/main/stable.txt)
curl -L --remote-name-all https://github.com/cilium/cilium-cli/releases/download/${CILIUM_CLI_VERSION}/cilium-linux-amd64.tar.gz
sudo tar xzvfC cilium-linux-amd64.tar.gz /usr/local/bin
# Run connectivity test
cilium status
cilium connectivity testPort-forward to access the Hubble UI:
kubectl -n kube-system port-forward svc/hubble-ui 12000:80
# Open http://localhost:12000 in your browserEdit group_vars/all.yml:
k3s_version: "v1.29.0+k3s1"Edit group_vars/all.yml:
cilium_version: "1.15.0"Edit group_vars/all.yml:
cluster_cidr: "10.42.0.0/16"
service_cidr: "10.43.0.0/16"# On server node
sudo journalctl -u k3s -f
# On agent nodes
sudo journalctl -u k3s-agent -fkubectl -n kube-system logs -l app.kubernetes.io/name=cilium-agent -fansible-playbook reset.yml
ansible-playbook site.ymlMIT